Re: signal handling
| From: | Stut | Date: | Fri, 08 Dec 2006 15:06:05 +0000 |
| Subject: | Re: signal handling | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-245654@lists.php.net to get a copy of this message | ||
Jochem Maas wrote:
Roman Neuhauser wrote:I have a system that forks to 'do work'. The main script sits in an infinite loop waiting for work, when it gets some it forks to process it. In that loop I have the following at the end... while (pcntl_wait($status, WNOHANG)) > 0)have I understood correctly that using pcntl_wait() means you can't do anything in the parent process until all children are dead? this seems strange. probably I'm mis-understanding and need to reread [alot of] stuff. but if it is true how do you go about tackling the signal handling in child processes AND at the same time have the parent process do something useful like ... interact/direct child processes, do other management tasks whilst child processes are running? maybe I'm misunderstanding the whole concept - it's nice to have that newbie feeling again ;-)The parent needs to wait(2) for its children. http://php.net/pcntl_wait
$workers--;That takes care of cleaning up finished processes while running. If the loop ends for any reason (e.g. it got stopped by a status change), I do... $started = time(); while ($workers > 0 and (time() - $started) < 300) {
pcntl_wait($status, WNOHANG);
$workers--;
sleep(1);
}
That sits waiting for up to 5 minutes for all processes to end.
-Stut
**