Re: Fork and zombies

From: Date: Tue, 17 Mar 2009 09:26:09 +0000
Subject: Re: Fork and zombies
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-290158@lists.php.net to get a copy of this message
Waynn Lue wrote: > I actually tried this in the meantime: > > $pid = pcntl_fork(); > if ($pid == -1) { > die("could not fork"); > } else if ($pid) { > // parent, return the child pid > echo "child pid $pid waiting\n"; > pcntl_waitpid($pid, $status); > if (pcntl_wifexited($status)) { > echo "finished [$status] waiting\n"; > return; > } else { > echo "ERROR\n"; > } > I think your waitpid() is in the wrong place, and at least you need use WNOHANG - unless you specifically want to wait for each child to finish before starting another one. > But it still has the same problem, and I'm also trying to avoid > pcntl_wait or pcntl_waitpid at all because I still want to do it > asynchronously. pcntl_wait(WNOHANG) will make everything work asynchronously. /Per -- Per Jessen, Zürich (5.8°C)

« previous php.general (#290158) next »