<?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-waitid.php',
    1 => 'pcntl_waitid',
    2 => '子プロセスの状態変化を待つ',
  ),
  'up' => 
  array (
    0 => 'ref.pcntl.php',
    1 => 'PCNTL 関数',
  ),
  'prev' => 
  array (
    0 => 'function.pcntl-wait.php',
    1 => 'pcntl_wait',
  ),
  'next' => 
  array (
    0 => 'function.pcntl-waitpid.php',
    1 => 'pcntl_waitpid',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/pcntl/functions/pcntl-waitid.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pcntl-waitid" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pcntl_waitid</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.4.0)</p><p class="refpurpose"><span class="refname">pcntl_waitid</span> &mdash; <span class="dc-title">子プロセスの状態変化を待つ</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pcntl-waitid-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pcntl_waitid</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">$idtype</code><span class="initializer"> = <strong><code><a href="pcntl.constants.php#constant.p-all">P_ALL</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$id</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></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">&$info</code><span class="initializer"> = []</span></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"> = <strong><code><a href="pcntl.constants.php#constant.wexited">WEXITED</a></code></strong></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.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   呼び出し元の子プロセスにおける 終了、停止、
   および/または 継続イベントに関連するステータス情報を取得します。
  </p>

  <p class="para">
   <strong><code><a href="pcntl.constants.php#constant.wnohang">WNOHANG</a></code></strong> フラグを渡さない限り、
   呼び出し元のプロセスはエラーが発生するか、
   以下を全て満たすステータス情報が利用できるようになるまでブロックします。
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      <code class="parameter">idtype</code> と <code class="parameter">id</code>
      で指定された一連の子プロセスのうちの、
      いずれかの子プロセスのステータス情報であること
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      ステータス情報の状態変化が、
      <code class="parameter">flags</code> で設定した状態変化フラグのひとつにマッチすること
     </span>
    </li>
   </ul>
  </p>

  <p class="para">
   マッチしたステータス情報が、<span class="function"><strong>pcntl_waitid()</strong></span>
   の呼び出し前に利用可能になった場合、
   呼び出しは直ぐに返ります。
   マッチしたステータス情報がふたつ以上の子プロセスで利用可能になった場合、
   それらのステータスの順番は不定です。
  </p>

  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    このドキュメントは <code class="literal">waitid</code>
    関数の POSIX 仕様を満たしていますし、
    Linux, NetBSD, FreeBSD に特有の追加パラメータもいくつか満たしています。
    システムで <code class="literal">waitid</code> がどのように動作するかの詳細は、
    システムの <code class="literal">waitid(2)</code> のマニュアルを参照ください。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pcntl-waitid-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt><code class="parameter">idtype</code></dt>
    <dt><code class="parameter">id</code></dt>
    <dd>
     <span class="simpara">
      <code class="parameter">idtype</code> と <code class="parameter">id</code> は、
      どの子プロセスを待つのかを指定するのに使います。
     </span>
     <table class="doctable table">
      <caption><strong>POSIX 標準の <code class="parameter">idtype</code> と <code class="parameter">id</code></strong></caption>
      
       <tbody class="tbody">
        <tr>
         <td><code class="parameter">idtype</code> が <code class="literal">P_ALL</code> の場合</td>
         <td>
          全ての子プロセスを待ちます。<code class="parameter">id</code> は無視されます。
         </td>
        </tr>

        <tr>
         <td><code class="parameter">idtype</code> が <code class="literal">P_PID</code> の場合</td>
         <td>
          プロセスID が <code class="parameter">id</code> に等しい子プロセスを待ちます。
         </td>
        </tr>

        <tr>
         <td><code class="parameter">idtype</code> が <code class="literal">P_PGID</code> の場合</td>
         <td>
          プロセスグループID が <code class="parameter">id</code> に等しいすべての子プロセスを待ちます。
         </td>
        </tr>

       </tbody>
      
     </table>

     <table class="doctable table">
      <caption><strong>Linux 特有の <code class="parameter">idtype</code> と <code class="parameter">id</code></strong></caption>
      
       <tbody class="tbody">
        <tr>
         <td><code class="parameter">idtype</code> が <code class="literal">P_PIDFD</code> の場合(Linux 5.4 以降)</td>
         <td>
          <code class="parameter">id</code> で指定した
          PID ファイルディスクリプタで参照している子プロセスを待ちます。
          (PID ファイルディスクリプタに関する詳しい情報は、
          Linux の <code class="literal">pidfd_open(2)</code> man ページを参照ください)
         </td>
        </tr>

       </tbody>
      
     </table>

     <table class="doctable table">
      <caption><strong>NetBSD と FreeBSD に特有の <code class="parameter">idtype</code> と <code class="parameter">id</code></strong></caption>
      
       <tbody class="tbody">
        <tr>
         <td>
          <code class="parameter">idtype</code> が <code class="literal">P_UID</code> の場合
         </td>
         <td>
          実効ユーザーID が <code class="parameter">id</code>
          に等しいプロセスを待ちます。
         </td>
        </tr>

        <tr>
         <td>
          <code class="parameter">idtype</code> が <code class="literal">P_GID</code> の場合
         </td>
         <td>
          実効グループID が <code class="parameter">id</code>
          に等しいプロセスを待ちます。
         </td>
        </tr>

        <tr>
         <td>
          <code class="parameter">idtype</code> が <code class="literal">P_SID</code> の場合
         </td>
         <td>
          セッションID が <code class="parameter">id</code> に等しいプロセスを待ちます。
          子プロセスが自分自身のセッションを開始していた場合、
          そのセッションIDはプロセスIDと等しくなります。
          そうでない場合、子プロセスのセッションIDは、
          呼び出し側のセッションIDとマッチします。
         </td>
        </tr>

       </tbody>
      
     </table>

     <table class="doctable table">
      <caption><strong>FreeBSD に特有の <code class="parameter">idtype</code> と <code class="parameter">id</code></strong></caption>
      
       <tbody class="tbody">
        <tr>
         <td>
          <code class="parameter">idtype</code> が <code class="literal">P_JAILID</code> の場合
         </td>
         <td>
          jail の識別子が <code class="parameter">id</code> に等しい
          jail 中のプロセスを待ちます。
         </td>
        </tr>

       </tbody>
      
     </table>

    </dd>
   
   
    <dt><code class="parameter">info</code></dt>
    <dd>
     <p class="para">
      <code class="parameter">info</code> には、
      シグナルに関する情報を含めた情報を設定します。
     </p>
     <p class="para">
      <code class="parameter">info</code> 配列には、以下のキーが含まれています:
      <ul class="simplelist">
       <li><code class="literal">signo</code>: Signal number</li>
       <li><code class="literal">errno</code>: System error number</li>
       <li><code class="literal">code</code>: Signal code</li>
       <li><code class="literal">status</code>: Exit value or signal</li>
       <li><code class="literal">pid</code>: Sending process ID</li>
       <li><code class="literal">uid</code>: Real user ID of sending process</li>
       <li><code class="literal">utime</code>: User time consumed</li>
       <li><code class="literal">stime</code>: System time consumed</li>
      </ul>
     </p>
    </dd>
   
   
    <dt><code class="parameter">flags</code></dt>
    <dd>
     <p class="para">
      <code class="parameter">flags</code> は、以下の定数を0個以上 OR で結んだ値です。　
      <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.wcontinued">WCONTINUED</a></code></strong></td>
          <td>
           以下にあてはまる任意の子プロセスについて、その状態が返されます:
           ジョブの制御停止から動作が継続して以降、
           そのステータスが報告されていないか、
           <span class="function"><strong>pcntl_waitid()</strong></span> を
           <strong><code><a href="pcntl.constants.php#constant.wnowait">WNOWAIT</a></code></strong>
           フラグ付きで呼び出したことによってのみステータスが報告された子プロセス。
          </td>
         </tr>

         <tr>
          <td><strong><code><a href="pcntl.constants.php#constant.wexited">WEXITED</a></code></strong></td>
          <td>
           終了したプロセスを待つ
          </td>
         </tr>

         <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.wnowait">WNOWAIT</a></code></strong></td>
          <td>
           <code class="parameter">info</code> で返されたプロセスの状態が
           waitable な状態であってもそのままにする。
           これはプロセスの状態に影響しません。つまり、
           この関数呼び出しが完了した後、
           プロセスを再度待つことができるということです。
          </td>
         </tr>

         <tr>
          <td><strong><code><a href="pcntl.constants.php#constant.wstopped">WSTOPPED</a></code></strong></td>
          <td>
           シグナルを受け取って停止した子プロセスについて、
           そのステータスが報告されていないか、
           <span class="function"><strong>pcntl_waitid()</strong></span> を
           <strong><code><a href="pcntl.constants.php#constant.wnowait">WNOWAIT</a></code></strong>
           フラグ付きで呼び出したことによってのみに報告された場合、
           その子プロセスの状態が返されます。
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>
   
   
    <dt><code class="parameter">resource_usage</code></dt>
    <dd>
     <p class="para">
      <code class="parameter">resource_usage</code> には、
      子プロセスからリソース利用状況の統計を含めた配列を設定します。
      この情報は、(FreeBSD のように)wait6 システムコールが利用可能な場合か、
      生の waitid システムコールを利用できる Linux でサポートされています。
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pcntl-waitid-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   <strong><code><a href="pcntl.constants.php#constant.wnohang">WNOHANG</a></code></strong> が指定されており、
   かつ <code class="parameter">idtype</code> と <code class="parameter">id</code>
   で指定された任意のプロセスでステータスが利用できない場合
   <span class="function"><strong>pcntl_waitid()</strong></span> は <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> を返します。
  </p>

  <p class="para">
   子プロセスのうちのひとつで、
   状態が変化した場合、
   <span class="function"><strong>pcntl_waitid()</strong></span> は <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> を返します。
  </p>

  <p class="para">
   上記以外の場合、<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> が返され、
   エラー番号 <code class="literal">errno</code> を取得するために
   <span class="function"><a href="function.pcntl-get-last-error.php" class="function">pcntl_get_last_error()</a></span> が使えます。
  </p>

  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    エラー番号 <code class="literal">errno</code> が取得できた場合、
    それに関連付けられたテキストメッセージを取得するために
    <span class="function"><a href="function.pcntl-strerror.php" class="function">pcntl_strerror()</a></span> が使えます。
   </p>
  </p></blockquote>
 </div>


  <div class="refsect1 errors" id="refsect1-function.pcntl-waitid-errors">
  <h3 class="title">エラー / 例外</h3>
  <table class="doctable table">
   <caption><strong>エラー番号 (<code class="literal">errno</code>) の値</strong></caption>
   
    <tbody class="tbody">
     <tr>
      <td><strong><code>ECHILD</code></strong></td>
      <td>
       呼び出し側のプロセスには、待っていない子プロセスはありません。
      </td>
     </tr>

     <tr>
      <td><strong><code>EINTR</code></strong></td>
      <td>
       <span class="function"><strong>pcntl_waitid()</strong></span> がシグナルで割り込まれました。
      </td>
     </tr>

     <tr>
      <td><strong><code>EINVAL</code></strong></td>
      <td>
       <code class="parameter">flags</code> に不正な値が指定されたか、
       <code class="parameter">idtype</code> と <code class="parameter">id</code>
       で不正なプロセスのセットを指定しました。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 changelog" id="refsect1-function.pcntl-waitid-changelog">
  <h3 class="title">変更履歴</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>バージョン</th>
      <th>説明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.5.0</td>
      <td>
       <code class="parameter">resource_usage</code> が追加されました。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.pcntl-waitid-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pcntl-waitpid.php" class="function" rel="rdfs-seeAlso">pcntl_waitpid()</a> - 待つかフォークした子プロセスのステータスを返す</span></li>
    <li><span class="function"><a href="function.pcntl-wait.php" class="function" rel="rdfs-seeAlso">pcntl_wait()</a> - 待つかフォークした子プロセスのステータスを返す</span></li>
    <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); ?>