I have the following test php to do a fork/spawn process, where the test also attempts to kill the child process (zombie) after is completes..
I\'d like to have a more e
Just use pcntl_wait(). There's no need to see if the child process has finished, just call pcntl_wait() and block until the child is reaped.
Avoid passing WNOHANG so that your parent process will sit and wait for a child to finish.
You can replace the reaping code you've written (starting at line 58 '$q=true;' of your example) with this:
$status = null;
do {
// You can use $status with pcntl_wifexited(), pcntl_wifstopped(),
// pcntl_wifsignaled(), pcntl_wexitstatus(), pcntl_wtermsig() and
// pcntl_wstopsig() if you need to.
$pid = pcntl_wait($status);
} while ($pid > 0);