Re: Starting background processed

From: Date: Thu, 02 Sep 1999 18:10:31 +0000
Subject: Re: Starting background processed
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-10461@lists.php.net to get a copy of this message
On Thu, 2 Sep 1999, Geocrawler.com wrote: > This message was sent from Geocrawler.com by "Klaus Reimer" <kr@ailis.de> > Be sure to reply to that address. > > Hi, > > I need to execute a shell script which starts a background process. > The script looks like this: > > #!/bin/bash > /path/daemon & > > I execute this script with exec but the command freezes until the > background process is stopped. If I use a real daemon instead of a > manual backgrounded process it works perfectly. What can I do, that > PHP executes this script and returns immediately? Your problem is that init (which is starting this script unless you're on some BSD system) waits for the termination of the /path/daemon process, even if you background it. The solution is "daemonizing" your process, which is usually done by calling setsid() and closing stdin, stdout and stderr. Linux has a "setsid" command, but I usually a program called "detach". You can find the source here: http://www.guardian.no/~ssb/detach-1.2.tar.gz - Stig

« previous php.dev (#10461) next »