Source of: /manual/en/function.pcntl-waitpid.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.pcntl.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.pcntl-waitpid.php',
1 => 'pcntl_waitpid',
),
'up' =>
array (
0 => 'ref.pcntl.php',
1 => 'PCNTL Functions',
),
'prev' =>
array (
0 => 'function.pcntl-wait.php',
1 => 'pcntl_wait',
),
'next' =>
array (
0 => 'function.pcntl-wexitstatus.php',
1 => 'pcntl_wexitstatus',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<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>
<a name="function.pcntl-waitpid.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">int</span> <span class="methodname"><b>pcntl_waitpid</b></span>
( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$pid</tt></span>
, <span class="methodparam"><span class="type">int</span> <tt class="parameter reference">&$status</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$options</tt><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 <i><tt class="parameter">pid</tt></i>
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 <i><tt class="parameter">pid</tt></i>
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>
<a name="function.pcntl-waitpid.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">pid</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The value of <i><tt class="parameter">pid</tt></i>
can be one of the following:
</p><table class="doctable table">
<caption><b>possible values for <i><tt class="parameter">pid</tt></i>
</b></caption>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left"><i>< -1</i></td>
<td align="left">
wait for any child process whose process group ID is equal to
the absolute value of <i><tt class="parameter">pid</tt></i>
.
</td>
</tr>
<tr valign="middle">
<td align="left"><i>-1</i></td>
<td align="left">
wait for any child process; this is the same behaviour that
the wait function exhibits.
</td>
</tr>
<tr valign="middle">
<td align="left"><i>0</i></td>
<td align="left">
wait for any child process whose process group ID is equal to
that of the calling process.
</td>
</tr>
<tr valign="middle">
<td align="left"><i>> 0</i></td>
<td align="left">
wait for the child whose process ID is equal to the value of
<i><tt class="parameter">pid</tt></i>
.
</td>
</tr>
</tbody>
</table>
<p>
</p>
<blockquote><p><b class="note">Note</b>:
Specifying <i>-1</i> as the <i><tt class="parameter">pid</tt></i>
is
equivalent to the functionality <a href="function.pcntl-wait.php" class="function">pcntl_wait()</a> provides
(minus <i><tt class="parameter">options</tt></i>
).
<br />
</p></blockquote>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">status</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
<b>pcntl_waitpid()</b> will store status information
in the <i><tt class="parameter">status</tt></i>
parameter which can be
evaluated using the following functions:
<a href="function.pcntl-wifexited.php" class="function">pcntl_wifexited()</a>,
<a href="function.pcntl-wifstopped.php" class="function">pcntl_wifstopped()</a>,
<a href="function.pcntl-wifsignaled.php" class="function">pcntl_wifsignaled()</a>,
<a href="function.pcntl-wexitstatus.php" class="function">pcntl_wexitstatus()</a>,
<a href="function.pcntl-wtermsig.php" class="function">pcntl_wtermsig()</a> and
<a href="function.pcntl-wstopsig.php" class="function">pcntl_wstopsig()</a>.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">options</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The value of <i><tt class="parameter">options</tt></i>
is the value of zero
or more of the following two global constants
<i>OR</i>'ed together:
</p><table class="doctable table">
<caption><b>possible values for <i><tt class="parameter">options</tt></i>
</b></caption>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left"><i>WNOHANG</i></td>
<td align="left">
return immediately if no child has exited.
</td>
</tr>
<tr valign="middle">
<td align="left"><i>WUNTRACED</i></td>
<td align="left">
return for children which are stopped, and whose status has
not been reported.
</td>
</tr>
</tbody>
</table>
<p>
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.pcntl-waitpid.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
<b>pcntl_waitpid()</b> returns the process ID of the
child which exited, -1 on error or zero if <b><tt class="constant">WNOHANG</tt></b> was used and no
child was available
</p>
</div>
<a name="function.pcntl-waitpid.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.pcntl-fork.php" class="function" rel="rdfs-seeAlso">pcntl_fork()</a> - Forks the currently running process</li>
<li class="member"><a href="function.pcntl-signal.php" class="function" rel="rdfs-seeAlso">pcntl_signal()</a> - Installs a signal handler</li>
<li class="member"><a href="function.pcntl-wifexited.php" class="function" rel="rdfs-seeAlso">pcntl_wifexited()</a> - Checks if status code represents a normal exit</li>
<li class="member"><a href="function.pcntl-wifstopped.php" class="function" rel="rdfs-seeAlso">pcntl_wifstopped()</a> - Checks whether the child process is currently stopped</li>
<li class="member"><a href="function.pcntl-wifsignaled.php" class="function" rel="rdfs-seeAlso">pcntl_wifsignaled()</a> - Checks whether the status code represents a termination due to a signal</li>
<li class="member"><a href="function.pcntl-wexitstatus.php" class="function" rel="rdfs-seeAlso">pcntl_wexitstatus()</a> - Returns the return code of a terminated child</li>
<li class="member"><a href="function.pcntl-wtermsig.php" class="function" rel="rdfs-seeAlso">pcntl_wtermsig()</a> - Returns the signal which caused the child to terminate</li>
<li class="member"><a href="function.pcntl-wstopsig.php" class="function" rel="rdfs-seeAlso">pcntl_wstopsig()</a> - Returns the signal which caused the child to stop</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>