Hudzilla.org - the homepage of Paul Hudson
Contents > Miscellaneous topics > Process control Wish List | Report Bug | About Me ]

16.1.7     Other ways to evaluate pcntl_waitpid()'s return value: pcntl_wifexited(), pcntl_wifsignaled(), pcntl_wifstopped(), pcntl_wtermsig(), and pcntl_wstopsig()

This is NOT the latest copy of this book; click here for the latest version.

int pcntl_wifexited ( int status)

int pcntl_wifsignaled ( int status)

int pcntl_wifstopped ( int status)

int pcntl_wtermsig ( int status)

int pcntl_wstopsig ( int status)

When a parent discovers through a call to pcntl_waitpid() that one of its children was terminated, the return value is a combination of how the child was terminated and the child's exit code. We have already looked at the function pcntl_wexitstatus(), which extracts the exit code from the return value of pcntl_waitpid(), however there are a selection of other functions that perform similar tasks and each take the same single parameter (the return value of pcntl_waitpid):

  • pcntl_wifexited(): returns true if the child process exited normal

  • pcntl_wifsignaled(): returns true if the child process exited as a result of it being sent a signal that was not handled

  • pcntl_wifstopped(): returns true if the child process is currently stopped.

Only one of the above will be true about a given child process at a time, and each of these has a matching function to determine why the state is how it is. The why function for pcntl_wifexited() is, of course, pcntl_wexitstatus(), and indeed that function has no meaning if used when pcntl_wifsignaled() returns true - a child process that did not exit normally will not send back an error code.

If you want to read the signal type that caused a child process to terminate, you would use the function pcntl_wtermsig(). Again, this only has meaning if pcntl_wifsignaled() returned true.

Finally, to read the signal type that caused a child process to stop, you would use the function pcntl_wstopsig(). This only has meaning if pcntl_wifstopped() returned true. Furthermore, as you can only read the status of stopped processes when WUNTRACED is specified as the third parameter to pcntl_waitpid(), both of these functions are meaningless if you call pcntl_waitpid() with just two parameters.





<< 16.1.6 Event-driven child termination   16.1.8 Running programs in the current process space: pcntl_exec() >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is eight plus one?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow