|
Posted by petersprc on 11/19/06 23:01
Hi,
pcntl_wait is actually equivalent to calling pcntl_waitpid with -1, so
that will work no problem.
Thomas wrote:
> Hi Peter,
>
> I ended up with this solution:
>
> function sig_handler($signo) {
> switch($signo){
> case SIGCHLD:
> $child = pcntl_wait($status,WNOHANG);
> if($child > 0){
> // Do something
> }
> }
> }
>
> pcntl_signal(SIGCHLD, "sig_handler");
>
> It seems to work like a charm, but it looks a bit different from your
> solutions. You sound like you know A LOT more about this than I do, so
> perhaps I could trouble you for a short explanation on the differences
> between the three solutions? :o)
>
> From my chair you second solution looks like the most "correct" way to
> go. Am I right?
>
> Sincerely,
> Thomas
>
>
> petersprc wrote:
> > Hi,
> >
> > The OS keeps the zombie around in case the parent process eventually
> > decides to retrieve the child's exit status information. You can tell
> > the OS you're not interested and to not keep zombies around using this:
> >
> > pcntl_signal(SIGCHLD, SIG_IGN);
> >
> > You could also trap SIGCHLD and check the child's exit status:
> >
> > function sigchld($signo) {
> > while (($pid = pcntl_waitpid(-1, $status, WNOHANG)) > 0) {
> > echo "Child with PID $pid returned " .
> > pcntl_wexitstatus($status) . ".\n";
> > }
> > }
> >
> > pcntl_signal(SIGCHLD, 'sigchld');
> >
Navigation:
[Reply to this message]
|