<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Waits on or returns the status of a forked child</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pcntl-wait.html">pcntl_wait</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pcntl-wexitstatus.html">pcntl_wexitstatus</a></div> <div class="up"><a href="ref.pcntl.html">PCNTL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.pcntl-waitpid" class="refentry"> <div class="refnamediv"> <h1 class="refname">pcntl_waitpid</h1> <p class="verinfo">(PHP 4 >= 4.1.0, PHP 5)</p><p class="refpurpose"><span class="refname">pcntl_waitpid</span> — <span class="dc-title">Waits on or returns the status of a forked child</span></p> </div> <div class="refsect1 description" id="refsect1-function.pcntl-waitpid-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>pcntl_waitpid</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$pid</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$status</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span> ] )</div> <p class="para rdfs-comment"> Suspends execution of the current process until a child as specified by the <em><code class="parameter">pid</code></em> argument has exited, or until a signal is delivered whose action is to terminate the current process or to call a signal handling function. </p> <p class="para"> If a child as requested by <em><code class="parameter">pid</code></em> has already exited by the time of the call (a so-called "zombie" process), the function returns immediately. Any system resources used by the child are freed. Please see your system's waitpid(2) man page for specific details as to how waitpid works on your system. </p> </div> <div class="refsect1 parameters" id="refsect1-function.pcntl-waitpid-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">pid</code></em></span> <dd> <p class="para"> The value of <em><code class="parameter">pid</code></em> can be one of the following: <table class="doctable table"> <caption><strong>possible values for <em><code class="parameter">pid</code></em></strong></caption> <tbody class="tbody"> <tr> <td><em>< -1</em></td> <td> wait for any child process whose process group ID is equal to the absolute value of <em><code class="parameter">pid</code></em>. </td> </tr> <tr> <td><em>-1</em></td> <td> wait for any child process; this is the same behaviour that the wait function exhibits. </td> </tr> <tr> <td><em>0</em></td> <td> wait for any child process whose process group ID is equal to that of the calling process. </td> </tr> <tr> <td><em>> 0</em></td> <td> wait for the child whose process ID is equal to the value of <em><code class="parameter">pid</code></em>. </td> </tr> </tbody> </table> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Specifying <em>-1</em> as the <em><code class="parameter">pid</code></em> is equivalent to the functionality <span class="function"><a href="function.pcntl-wait.html" class="function">pcntl_wait()</a></span> provides (minus <em><code class="parameter">options</code></em>). </p> </p></blockquote> </dd> </dt> <dt> <span class="term"><em><code class="parameter">status</code></em></span> <dd> <p class="para"> <span class="function"><strong>pcntl_waitpid()</strong></span> will store status information in the <em><code class="parameter">status</code></em> parameter which can be evaluated using the following functions: <span class="function"><a href="function.pcntl-wifexited.html" class="function">pcntl_wifexited()</a></span>, <span class="function"><a href="function.pcntl-wifstopped.html" class="function">pcntl_wifstopped()</a></span>, <span class="function"><a href="function.pcntl-wifsignaled.html" class="function">pcntl_wifsignaled()</a></span>, <span class="function"><a href="function.pcntl-wexitstatus.html" class="function">pcntl_wexitstatus()</a></span>, <span class="function"><a href="function.pcntl-wtermsig.html" class="function">pcntl_wtermsig()</a></span> and <span class="function"><a href="function.pcntl-wstopsig.html" class="function">pcntl_wstopsig()</a></span>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">options</code></em></span> <dd> <p class="para"> The value of <em><code class="parameter">options</code></em> is the value of zero or more of the following two global constants <em>OR</em>'ed together: <table class="doctable table"> <caption><strong>possible values for <em><code class="parameter">options</code></em></strong></caption> <tbody class="tbody"> <tr> <td><em>WNOHANG</em></td> <td> return immediately if no child has exited. </td> </tr> <tr> <td><em>WUNTRACED</em></td> <td> return for children which are stopped, and whose status has not been reported. </td> </tr> </tbody> </table> </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.pcntl-waitpid-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> <span class="function"><strong>pcntl_waitpid()</strong></span> returns the process ID of the child which exited, -1 on error or zero if <strong><code>WNOHANG</code></strong> was used and no child was available </p> </div> <div class="refsect1 seealso" id="refsect1-function.pcntl-waitpid-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.pcntl-fork.html" class="function" rel="rdfs-seeAlso">pcntl_fork()</a> - Forks the currently running process</span></li> <li class="member"> <span class="function"><a href="function.pcntl-signal.html" class="function" rel="rdfs-seeAlso">pcntl_signal()</a> - Installs a signal handler</span></li> <li class="member"> <span class="function"><a href="function.pcntl-wifexited.html" class="function" rel="rdfs-seeAlso">pcntl_wifexited()</a> - Checks if status code represents a normal exit</span></li> <li class="member"> <span class="function"><a href="function.pcntl-wifstopped.html" class="function" rel="rdfs-seeAlso">pcntl_wifstopped()</a> - Checks whether the child process is currently stopped</span></li> <li class="member"> <span class="function"><a href="function.pcntl-wifsignaled.html" class="function" rel="rdfs-seeAlso">pcntl_wifsignaled()</a> - Checks whether the status code represents a termination due to a signal</span></li> <li class="member"> <span class="function"><a href="function.pcntl-wexitstatus.html" class="function" rel="rdfs-seeAlso">pcntl_wexitstatus()</a> - Returns the return code of a terminated child</span></li> <li class="member"> <span class="function"><a href="function.pcntl-wtermsig.html" class="function" rel="rdfs-seeAlso">pcntl_wtermsig()</a> - Returns the signal which caused the child to terminate</span></li> <li class="member"> <span class="function"><a href="function.pcntl-wstopsig.html" class="function" rel="rdfs-seeAlso">pcntl_wstopsig()</a> - Returns the signal which caused the child to stop</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pcntl-wait.html">pcntl_wait</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pcntl-wexitstatus.html">pcntl_wexitstatus</a></div> <div class="up"><a href="ref.pcntl.html">PCNTL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>