From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Ehud Karni" Newsgroups: gmane.emacs.devel Subject: Re: trying to fork away from Emacs in a sub-process from elisp Date: Wed, 10 Aug 2005 12:21:43 +0300 Organization: Mivtach-Simon Insurance agencies Message-ID: <200508100921.j7A9LhSG004360@beta.mvs.co.il> References: <874q9yg75b.fsf@kanga.tapsellferrier.co.uk> Reply-To: ehud@unix.mvs.co.il NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-8-i Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1123666559 19778 80.91.229.2 (10 Aug 2005 09:35:59 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 10 Aug 2005 09:35:59 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 10 11:35:54 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1E2mz3-0006su-5i for ged-emacs-devel@m.gmane.org; Wed, 10 Aug 2005 11:34:49 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E2n29-0002l1-Oq for ged-emacs-devel@m.gmane.org; Wed, 10 Aug 2005 05:38:01 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1E2my0-0001jM-6C for emacs-devel@gnu.org; Wed, 10 Aug 2005 05:33:45 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1E2mxu-0001go-Dr for emacs-devel@gnu.org; Wed, 10 Aug 2005 05:33:38 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E2mxt-0001bK-V4 for emacs-devel@gnu.org; Wed, 10 Aug 2005 05:33:38 -0400 Original-Received: from [193.16.147.12] (helo=unix.mvs.co.il) by monty-python.gnu.org with esmtp (Exim 4.34) id 1E2n0Z-0002if-4d for emacs-devel@gnu.org; Wed, 10 Aug 2005 05:36:23 -0400 Original-Received: from beta.mvs.co.il (beta [10.253.0.3]) by unix.mvs.co.il (8.13.0/8.13.0) with ESMTP id j7A9Lks7016107 for ; Wed, 10 Aug 2005 12:21:46 +0300 Original-Received: from beta.mvs.co.il (localhost [127.0.0.1]) by beta.mvs.co.il (8.13.4/8.13.4) with ESMTP id j7A9LiU1004363 for ; Wed, 10 Aug 2005 12:21:45 +0300 Original-Received: (from root@localhost) by beta.mvs.co.il (8.13.4/8.13.4/Submit) id j7A9LhSG004360; Wed, 10 Aug 2005 12:21:43 +0300 Original-To: nferrier@tapsellferrier.co.uk In-reply-to: <874q9yg75b.fsf@kanga.tapsellferrier.co.uk> (message from Nic Ferrier on Tue, 09 Aug 2005 21:57:52 +0100) X-Mailer: Emacs 21.3.1 rmail (send-msg 1.108) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:41851 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:41851 On Tue, 09 Aug 2005 21:57:52 +0100, Nic Ferrier wrote: > > I'm writing a tiny image viewer to be used in conjunction with emacs. > > I've constructed the viewer so that it need only start once. It sets > up a named pipe so that all subsequent invocations talk to the initial > program over the named pipe (imagemagick is supposed to do this with > the -remote option, but it doesn't work). > > I realize that I *could* implement the > when-is-the-process-the-first-process logic in elisp... but I thought > it was simpler and neater to have the client program simply daemonize > itself on the fifo setup invocation. > > Trouble is, when the program daemonizes, Emacs doesn't seem to > recognize it and carries on waiting (waiting for what I'm not sure). > > Is there some reason why client programs cannot daemonize when started > by emacs? > > > > For reference, my client program is written in python and is following > this basic procedure: > > fork > child: > setsid > fork > child: > chdir / > close stdout > close stdin > close stderr > I don't know python, but I wrote a small bash script for the same purpose. I background with nohup. Below are my lisp and bash code. Also a ps output when displaying 3 files: a doc, a tiff, an html. Ehud. (defun ek-view-this-file () "View this file as graphic (on X) in background" (interactive) (let ((files (dired-get-marked-files t current-prefix-arg))) (dired-do-shell-command "ek-view.sh *" t files))) (define-key dired-mode-map "s" 'ek-view-this-file) #! /bin/sh # View (on X) a graphic file (arg) # -------------------------------------------------- xmsg () { BGC=${2:-khaki} SPC=" " nohup xmessage \ -background $BGC -foreground Black -center -file "$1" \ -title "$1" -xrm "$1.Scroll:whenNeeded" \ -buttons "$SPC E x i t $SPC" > /dev/null & sleep 1 # allow xmessage to start } # ---------------------------------------------------------------------- exec 2>> /dev/null # do not show anything ! case `which display` in "/usr/bin/"* ) VIEW=display ;; # use display (from Image Magic) * ) VIEW=xview ;; # any other case esac case `which firefox` in "/usr/bin/"* ) HTMV=firefox ;; # use firefox (when available) * ) HTMV=mozilla ;; # no firefox, use mozilla esac for FLN in "$@" do lFLN=`echo "$FLN" | tr "A-Z" "a-z"` # name in lower case case "$lFLN" in *htm | *html) # browser URL=file://`pwd`/"$FLN" # file URL nohup /usr/bin/$HTMV "$URL" > /dev/null & ;; # html *pdf ) nohup xpdf "$FLN" > /dev/null & ;; # PDF file *mpg | *mpeg ) nohup xanim "$FLN" > /dev/null & ;; # MPEG - movie *.doc ) # M$ Word document catdoc "$FLN" | fribidi --charset ISO8859-8 --width 90 --rtl > "${FLN}_h_txt" xmsg "${FLN}_h_txt" # show message catdoc "$FLN" | fribidi --charset ISO8859-8 --width 90 --ltr > "${FLN}_e_txt" xmsg "${FLN}_e_txt" cyan sleep 2 # Allow xmessage to start rm -f "${FLN}_h_txt" "${FLN}_e_txt" ;; # remove input *.txt ) xmsg "$FLN" # show message cat "$FLN" | fribidi --charset ISO8859-8 --width 90 --ltr > "${FLN}_e_txt" xmsg "${FLN}_e_txt" cyan sleep 2 # Allow xmessage to start rm -f "${FLN}_e_txt" ;; # remove input * ) nohup $VIEW "$FLN" > /dev/null & ;; # any other picture esac done exec sleep 2 # Don't kill STARTING background processes ############################## ek-view.sh ############################## UID PID PPID SID START TIME COMMAND ehud 7100 1 6546 Jul 26 07:14:30 emacs-21.3 -geometry 130x62+0+0 /procom/home/ehud/emacs-21 ehud 26767 1 26745 12:03:04 0:00 xmessage -background khaki -foreground Black -center -file Simon.405.doc_h_txt -title ehud 26771 1 26745 12:03:05 0:00 xmessage -background cyan -foreground Black -center -file Simon.405.doc_e_txt -title S ehud 26778 1 26745 12:03:08 0:01 display Ishur-mas-2006.tiff ehud 26783 1 26745 12:03:08 0:00 /bin/sh /usr/lib/firefox-1.0.4/firefox file:///procom/home/ehud/mail/tmp/zeev-crtf.htm ehud 26800 26783 26745 12:03:27 0:00 /bin/sh /usr/lib/firefox-1.0.4/run-mozilla.sh /usr/lib/firefox-1.0.4/firefox-bin file: ehud 26805 26800 26745 12:03:27 0:03 /usr/lib/firefox-1.0.4/firefox-bin file:///procom/home/ehud/mail/tmp/zeev-crtf.html -- Ehud Karni Tel: +972-3-7966-561 /"\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ GnuPG: 98EA398D Better Safe Than Sorry