PHP Function PCNTL_Waitpid
php function pcntl_waitpid is a PHP function that makes use of the PCNTL library (as used by Apache). This PHP library provides support for process forking, signal handling, and process management. PCNTL is only available on Unix systems, so this article is intended for those developers who have a PHP environment running on a Linux or other Unix platform. If you are not using a Unix system to host your web site or if you do not have the PCNTL extension installed then you should skip this article and instead read one of our other articles on PHP forking and threading.
The pcntl_waitpid() function suspends execution of the calling process until a child indicated by the pid argument exits. If the child has already exited by the time the call is made (a so-called zombie process), then the function returns immediately and any system resources that were used by the child are freed up. If the pid is not an absolute value then the function will wait for any child process that has the same process group ID as the calling process.
The return value of the child process is stored in a variable called $status. This value is a Boolean that will be set to the value of the signal that was generated by the child process when it called pcntl_waitpid(). The handling of signals is a complex topic and should be discussed in a separate document. For more information on how to handle signals in a PHP program please consult a Unix programming manual or the getpgrp(2) man page on your operating system.