Date: Sat, 6 Jun 2009 16:42:24 -0400 (EDT) From: vogelke+unix@pobox.com (Karl Vogel) To: freebsd-questions@freebsd.org Subject: Re: Can a Bourn Shell Script put itself in the background? Message-ID: <20090606204224.CDFD2BED3@kev.msw.wpafb.af.mil> In-Reply-To: <200906061210.n56CAl8e018383@dc.cis.okstate.edu> (message from Martin McCormick on Sat, 06 Jun 2009 07:10:47 -0500)
next in thread | previous in thread | raw e-mail | index | archive | help
>> "Barry Byrne" writes: B> I think the simplest thing would be to write a little wrapper script B> that calls your other script. B> B> #!/bin/sh B> echo "Stating Daemon Now" B> /path/to/mainscript & You might be better off using daemon to make sure you're detached from the controlling terminal. Other advantages are changing the working directory to / in case you need to unmount the filesystem from which the original program was run, and properly handling stdin/stdout/stderr. >> On Sat, 06 Jun 2009 07:10:47 -0500, >> Martin McCormick <martin@dc.cis.okstate.edu> said: M> [...] the output can be redirected to /dev/null or anywhere M> else when you call the script. To kill it, do M> ps ax | grep SCRIPTNAME | grep -v grep If you're looking for an easy way to kill "mainscript", have it store its process-id somewhere: echo $$ > /var/run/`basename $0`.pid M> As with all scripts that can start background processes, be careful with M> loops and such... If you're working on each file in a directory, it helps to add something like this to the inner loop: test -f "stop" && echo stopped at user request && exit 1 This way, you can just "touch stop" if something goes to hell instead of having to grub around in the process table. -- Karl Vogel I don't speak for the USAF or my company Therapy is expensive. Popping bubble wrap is cheap. You choose. --bumper sticker
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090606204224.CDFD2BED3>