[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: trying to fork away from Emacs in a sub-process from elisp
From: |
Ehud Karni |
Subject: |
Re: trying to fork away from Emacs in a sub-process from elisp |
Date: |
Wed, 10 Aug 2005 12:21:43 +0300 |
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 <http://www.keyserver.net/> Better Safe Than Sorry