<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.pcntl-wait.php',
    1 => 'pcntl_wait',
    2 => '等待或返回 fork 的子进程状态',
  ),
  'up' => 
  array (
    0 => 'ref.pcntl.php',
    1 => 'PCNTL 函数',
  ),
  'prev' => 
  array (
    0 => 'function.pcntl-unshare.php',
    1 => 'pcntl_unshare',
  ),
  'next' => 
  array (
    0 => 'function.pcntl-waitid.php',
    1 => 'pcntl_waitid',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/pcntl/functions/pcntl-wait.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pcntl-wait" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pcntl_wait</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pcntl_wait</span> &mdash; <span class="dc-title">等待或返回 fork 的子进程状态</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.pcntl-wait-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pcntl_wait</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter reference">&$status</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter reference">&$resource_usage</code><span class="initializer"> = []</span></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   wait 函数挂起当前进程的执行直到一个子进程退出或接收到一个信号要求中断当前进程或调用一个信号处理函数。如果一个子进程在调用此函数时已经退出（俗称僵尸进程），此函数立刻返回。子进程使用的所有系统资源将被释放。关于 wait 在您系统上工作的详细规范请查看您系统的 wait（2）手册。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    这个函数等同于以 <code class="literal">-1</code> 作为参数 <code class="parameter">process_id</code>
    的值并且没有 <code class="parameter">flags</code> 参数来调用 <span class="function"><a href="function.pcntl-waitpid.php" class="function">pcntl_waitpid()</a></span>
    函数。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pcntl-wait-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">status</code></dt>
     <dd>
      <p class="para">
       <span class="function"><strong>pcntl_wait()</strong></span> 将会存储状态信息到 <code class="parameter">status</code>
       参数上，这个通过 <code class="parameter">status</code> 参数返回的状态信息可以用以下函数
       <span class="function"><a href="function.pcntl-wifexited.php" class="function">pcntl_wifexited()</a></span>、
       <span class="function"><a href="function.pcntl-wifstopped.php" class="function">pcntl_wifstopped()</a></span>、
       <span class="function"><a href="function.pcntl-wifsignaled.php" class="function">pcntl_wifsignaled()</a></span>、
       <span class="function"><a href="function.pcntl-wexitstatus.php" class="function">pcntl_wexitstatus()</a></span>、
       <span class="function"><a href="function.pcntl-wtermsig.php" class="function">pcntl_wtermsig()</a></span> 以及
       <span class="function"><a href="function.pcntl-wstopsig.php" class="function">pcntl_wstopsig()</a></span> 获取其具体的值。
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
      如果操作系统（多数 BSD 类系统）允许使用 wait3，可以提供可选的 <code class="parameter">flags</code>
      参数。如果这个参数没有提供，wait 将会被用作系统调用。如果 wait3 不可用，提供参数
      <code class="parameter">flags</code> 不会有任何效果。<code class="parameter">flags</code> 的值可以是以下两个常量中
      0 个或多个 <code class="literal">OR</code> 运算的结果：
       <table class="doctable table">
        <caption><strong><code class="parameter">flags</code> 可用值</strong></caption>
        
         <tbody class="tbody">
          <tr>
           <td><strong><code><a href="pcntl.constants.php#constant.wnohang">WNOHANG</a></code></strong></td>
           <td>
            如果没有子进程退出立刻返回。
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="pcntl.constants.php#constant.wuntraced">WUNTRACED</a></code></strong></td>
           <td>
           子进程已经退出并且其状态未报告时返回。
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pcntl-wait-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>pcntl_wait()</strong></span> 返回退出的子进程进程号，发生错误时返回 -1，如果提供了 WNOHANG 作为 option（wait3 可用的系统）并且没有可用子进程时返回 0。
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pcntl-wait-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pcntl-fork.php" class="function" rel="rdfs-seeAlso">pcntl_fork()</a> - 在当前进程当前位置产生分叉（fork）</span></li>
    <li><span class="function"><a href="function.pcntl-signal.php" class="function" rel="rdfs-seeAlso">pcntl_signal()</a> - 安装信号处理程序</span></li>
    <li><span class="function"><a href="function.pcntl-wifexited.php" class="function" rel="rdfs-seeAlso">pcntl_wifexited()</a> - 检查状态代码是否代表一个正常的退出</span></li>
    <li><span class="function"><a href="function.pcntl-wifstopped.php" class="function" rel="rdfs-seeAlso">pcntl_wifstopped()</a> - 检查子进程当前是否已经停止</span></li>
    <li><span class="function"><a href="function.pcntl-wifsignaled.php" class="function" rel="rdfs-seeAlso">pcntl_wifsignaled()</a> - 检查子进程状态码是否代表由于某个信号而中断</span></li>
    <li><span class="function"><a href="function.pcntl-wexitstatus.php" class="function" rel="rdfs-seeAlso">pcntl_wexitstatus()</a> - 返回一个中断的子进程的返回代码</span></li>
    <li><span class="function"><a href="function.pcntl-wtermsig.php" class="function" rel="rdfs-seeAlso">pcntl_wtermsig()</a> - 返回导致子进程中断的信号</span></li>
    <li><span class="function"><a href="function.pcntl-wstopsig.php" class="function" rel="rdfs-seeAlso">pcntl_wstopsig()</a> - 返回导致子进程停止的信号</span></li>
    <li><span class="function"><a href="function.pcntl-waitpid.php" class="function" rel="rdfs-seeAlso">pcntl_waitpid()</a> - 等待或返回 fork 的子进程状态</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>