uTools-Manuals/docs/php/pcntl_waitpid.html
2019-04-08 23:22:26 +08:00

184 lines
7.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>等待或返回fork的子进程状态</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.pcntl-waitpid" class="refentry">
<div class="refnamediv">
<h1 class="refname">pcntl_waitpid</h1>
<p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">pcntl_waitpid</span> &mdash; <span class="dc-title">等待或返回fork的子进程状态</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.pcntl-waitpid-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<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>
] ) : <span class="type">int</span></div>
<p class="para rdfs-comment">
挂起当前进程的执行直到参数<code class="parameter">pid</code>指定的进程号的进程退出,
或接收到一个信号要求中断当前进程或调用一个信号处理函数。
</p>
<p class="para">
如果<code class="parameter">pid</code>指定的子进程在此函数调用时已经退出(俗称僵尸进程),此函数
将立刻返回。关于waitpid更详细的规范请参见您系统的waitpid2手册。
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.pcntl-waitpid-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">pid</code></dt>
<dd>
<p class="para">
参数<code class="parameter">pid</code>的值可以是以下之一:
<table class="doctable table">
<caption><strong><code class="parameter">pid</code>可选值</strong></caption>
<tbody class="tbody">
<tr>
<td><em>&lt; -1</em></td>
<td>
等待任意进程组ID等于参数<code class="parameter">pid</code>给定值的绝对值的进程。
</td>
</tr>
<tr>
<td><em>-1</em></td>
<td>
等待任意子进程;与pcntl_wait函数行为一致。
</td>
</tr>
<tr>
<td><em>0</em></td>
<td>
等待任意与调用进程组ID相同的子进程。
</td>
</tr>
<tr>
<td><em>&gt; 0</em></td>
<td>
等待进程号等于参数<code class="parameter">pid</code>值的子进程。
</td>
</tr>
</tbody>
</table>
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
指定<em>-1</em>作为<code class="parameter">pid</code>的值等同于<span class="function"><a href="pcntl_wait.html" class="function">pcntl_wait()</a></span>
提供(负的<code class="parameter">options</code>)。
</p>
</p></blockquote>
</dd>
<dt>
<code class="parameter">status</code></dt>
<dd>
<p class="para">
<span class="function"><strong>pcntl_waitpid()</strong></span>将会存储状态信息到<code class="parameter">status</code>
参数上,这个通过<code class="parameter">status</code>参数返回的状态信息可以用以下函数
<span class="function"><a href="pcntl_wifexited.html" class="function">pcntl_wifexited()</a></span>,
<span class="function"><a href="pcntl_wifstopped.html" class="function">pcntl_wifstopped()</a></span>,
<span class="function"><a href="pcntl_wifsignaled.html" class="function">pcntl_wifsignaled()</a></span>,
<span class="function"><a href="pcntl_wexitstatus.html" class="function">pcntl_wexitstatus()</a></span>,
<span class="function"><a href="pcntl_wtermsig.html" class="function">pcntl_wtermsig()</a></span>以及
<span class="function"><a href="pcntl_wstopsig.html" class="function">pcntl_wstopsig()</a></span>获取其具体的值。
</p>
</dd>
<dt>
<code class="parameter">options</code></dt>
<dd>
<p class="para">
如果您的操作系统多数BSD类系统允许使用wait3您可以提供可选的<code class="parameter">options</code>
参数。如果这个参数没有提供wait将会被用作系统调用。如果wait3不可用提供参数
<code class="parameter">options</code>不会有任何效果。<code class="parameter">options</code>的值可以是0
或者以下两个常量或两个常量“或运算”结果(即两个常量代表意义都有效)。
<table class="doctable table">
<caption><strong><code class="parameter">options</code>可用的值</strong></caption>
<tbody class="tbody">
<tr>
<td><em>WNOHANG</em></td>
<td>
如果没有子进程退出立刻返回。
</td>
</tr>
<tr>
<td><em>WUNTRACED</em></td>
<td>
子进程已经退出并且其状态未报告时返回。
</td>
</tr>
</tbody>
</table>
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.pcntl-waitpid-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
<span class="function"><strong>pcntl_waitpid()</strong></span>返回退出的子进程进程号,发生错误时返回-1,如果提供了
<strong><code>WNOHANG</code></strong>作为optionwait3可用的系统并且没有可用子进程时返回0。
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.pcntl-waitpid-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="pcntl_fork.html" class="function" rel="rdfs-seeAlso">pcntl_fork()</a> - 在当前进程当前位置产生分支子进程。译注fork是创建了一个子进程父进程和子进程
都从fork的位置开始向下继续执行不同的是父进程执行过程中得到的fork返回值为子进程
而子进程得到的是0。</span></li>
<li class="member"><span class="function"><a href="pcntl_signal.html" class="function" rel="rdfs-seeAlso">pcntl_signal()</a> - 安装一个信号处理器</span></li>
<li class="member"><span class="function"><a href="pcntl_wifexited.html" class="function" rel="rdfs-seeAlso">pcntl_wifexited()</a> - 检查状态代码是否代表一个正常的退出。</span></li>
<li class="member"><span class="function"><a href="pcntl_wifstopped.html" class="function" rel="rdfs-seeAlso">pcntl_wifstopped()</a> - 检查子进程当前是否已经停止</span></li>
<li class="member"><span class="function"><a href="pcntl_wifsignaled.html" class="function" rel="rdfs-seeAlso">pcntl_wifsignaled()</a> - 检查子进程状态码是否代表由于某个信号而中断</span></li>
<li class="member"><span class="function"><a href="pcntl_wexitstatus.html" class="function" rel="rdfs-seeAlso">pcntl_wexitstatus()</a> - 返回一个中断的子进程的返回代码</span></li>
<li class="member"><span class="function"><a href="pcntl_wtermsig.html" class="function" rel="rdfs-seeAlso">pcntl_wtermsig()</a> - 返回导致子进程中断的信号</span></li>
<li class="member"><span class="function"><a href="pcntl_wstopsig.html" class="function" rel="rdfs-seeAlso">pcntl_wstopsig()</a> - 返回导致子进程停止的信号</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>