Search This Blog

Thursday, May 23, 2013

A problem with pcntl_fork - PHP

A problem with pcntl_fork - PHP:

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');

No comments:

Post a Comment