<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.pcntl-waitpid.php',
    1 => 'pcntl_waitpid',
    2 => '待つかフォークした子プロセスのステータスを返す',
  ),
  'up' => 
  array (
    0 => 'ref.pcntl.php',
    1 => 'PCNTL 関数',
  ),
  'prev' => 
  array (
    0 => 'function.pcntl-waitid.php',
    1 => 'pcntl_waitid',
  ),
  'next' => 
  array (
    0 => 'function.pcntl-wexitstatus.php',
    1 => 'pcntl_wexitstatus',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/pcntl/functions/pcntl-waitpid.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<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, PHP 8)</p><p class="refpurpose"><span class="refname">pcntl_waitpid</span> &mdash; <span class="dc-title">待つかフォークした子プロセスのステータスを返す</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>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$process_id</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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><br>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   引数 <code class="parameter">process_id</code> で指定した子プロセスが終了する・
   現在のプロセスを終了させるシグナルが送信される・シグナル処理関数を
   コールするシグナルが送信される
   のいずれかが発生するまで、現在のプロセスの実行を中断します。
  </p>
  <p class="para">
   <code class="parameter">process_id</code> でリクエストされた子プロセスが、
   コール時に既に終了している場合(&quot;ゾンビ&quot;プロセスと呼ばれます)、
   この関数は直ちに処理を返します。
   子プロセスにより使用される全てのシステム
   リソースは、解放されます。waitpid のシステムでの動作に関する詳細は、
   システムの waitpid(2) についての man ページを参照ください。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pcntl-waitpid-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">process_id</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">process_id</code> の値は、次のどれかとなります。
       <table class="doctable table">
        <caption><strong><code class="parameter">process_id</code> のとりうる値</strong></caption>
        
         <tbody class="tbody">
          <tr>
           <td><code class="literal">&lt; -1</code></td>
           <td>
            プロセスグループ ID が <code class="parameter">process_id</code> の絶対値に等しい
            子プロセスを待ちます。
           </td>
          </tr>

          <tr>
           <td><code class="literal">-1</code></td>
           <td>
            全ての子プロセスを待ちます。これは、
            <span class="function"><a href="function.pcntl-wait.php" class="function">pcntl_wait()</a></span> 関数の動作と同じです。
           </td>
          </tr>

          <tr>
           <td><code class="literal">0</code></td>
           <td>
            プロセスグループ ID がコール側のプロセスと等しい子プロセスを
            待ちます。
           </td>
          </tr>

          <tr>
           <td><code class="literal">&gt; 0</code></td>
           <td>
            プロセス ID が <code class="parameter">process_id</code> の値に等しい
            子プロセスを待ちます。
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        <code class="literal">-1</code> を
        <code class="parameter">process_id</code> に指定した際の動きは、
        <span class="function"><a href="function.pcntl-wait.php" class="function">pcntl_wait()</a></span> の機能と
        (<code class="parameter">flags</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> の中にステータス情報を保存します。
       このステータスは、次の関数を用いて評価可能です。
       <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">
       <code class="parameter">flags</code> の値は、次の 2 つのグローバル定数の
       ゼロまたはそれ以上の論理和です。
       <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-waitpid-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   <span class="function"><strong>pcntl_waitpid()</strong></span> は、終了した子プロセスの
   プロセス ID を返します。エラーの場合は -1、<strong><code><a href="pcntl.constants.php#constant.wnohang">WNOHANG</a></code></strong> が使用され、
   子プロセスが利用できない場合に 0 を返します。
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pcntl-waitpid-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> - 現在実行中のプロセスをフォークする</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>
   </ul>
  </p>
 </div>


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