From owner-freebsd-questions@FreeBSD.ORG Sat Jun 6 20:44:28 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2372A1065680 for ; Sat, 6 Jun 2009 20:44:28 +0000 (UTC) (envelope-from vogelke@hcst.com) Received: from beta.hcst.com (beta.hcst.com [192.52.183.241]) by mx1.freebsd.org (Postfix) with ESMTP id D2E028FC15 for ; Sat, 6 Jun 2009 20:44:27 +0000 (UTC) (envelope-from vogelke@hcst.com) Received: from beta.hcst.com (localhost [127.0.0.1]) by beta.hcst.com (8.13.8/8.13.8/Debian-3) with ESMTP id n56KiQPD020257 for ; Sat, 6 Jun 2009 16:44:26 -0400 Received: (from vogelke@localhost) by beta.hcst.com (8.13.8/8.13.8/Submit) id n56KiQTP020256; Sat, 6 Jun 2009 16:44:26 -0400 Received: by kev.msw.wpafb.af.mil (Postfix, from userid 32768) id CDFD2BED3; Sat, 6 Jun 2009 16:42:24 -0400 (EDT) To: freebsd-questions@freebsd.org In-reply-to: <200906061210.n56CAl8e018383@dc.cis.okstate.edu> (message from Martin McCormick on Sat, 06 Jun 2009 07:10:47 -0500) Organization: Oasis Systems Inc. X-Disclaimer: I don't speak for the USAF or Oasis. X-GPG-ID: 1024D/711752A0 2006-06-27 Karl Vogel X-GPG-Fingerprint: 56EB 6DBF 4224 C953 F417 CC99 4C7C 7D46 7117 52A0 Message-Id: <20090606204224.CDFD2BED3@kev.msw.wpafb.af.mil> Date: Sat, 6 Jun 2009 16:42:24 -0400 (EDT) From: vogelke+unix@pobox.com (Karl Vogel) Subject: Re: Can a Bourn Shell Script put itself in the background? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: vogelke+unix@pobox.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Jun 2009 20:44:28 -0000 >> "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 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