<?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 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.pcntl-waitid.php',
    1 => 'pcntl_waitid',
    2 => 'Waits for a child process to change state',
  ),
  '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' => 'en',
    '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">Waits for a child process to change state</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pcntl-waitid-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">function</span> <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">
   Obtains status information pertaining to termination, stop, and/or continue
   events in one of the caller&#039;s child processes.
  </p>

  <p class="para">
   Unless <strong><code><a href="pcntl.constants.php#constant.wnohang">WNOHANG</a></code></strong> flag is passed, the calling process will
   become blocked until an error occurs, or status information becomes
   available that satisfies all of the following:
   <ul class="itemizedlist">
    <li class="listitem">
     <p class="simpara">
      The status information is from one of the child processes in the set of
      child processes specified by the <code class="parameter">idtype</code> and
      <code class="parameter">id</code> arguments.
     </p>
    </li>
    <li class="listitem">
     <p class="simpara">
      The state change in the status information matches one of the state change
      flags set in the <code class="parameter">flags</code> argument.
     </p>
    </li>
   </ul>
  </p>

  <p class="para">
   If matching status information is available prior to the call to
   <span class="function"><strong>pcntl_waitid()</strong></span>, return shall be immediate. If matching
   status information is available for two or more child processes, the order
   in which their status is reported is unspecified.
  </p>

  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    This documentation covers the POSIX specification of the
    <code class="literal">waitid</code> function, along with some additional parameters
    specific to implementations on Linux, NetBSD and FreeBSD. Please see your
    system&#039;s <code class="literal">waitid(2)</code> man page for specific details as to
    how <code class="literal">waitid</code> works on your system.
   </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>
     <p class="simpara">
      The <code class="parameter">idtype</code> and <code class="parameter">id</code> arguments
      are used to specify which children to wait for.
     </p>
     <table class="doctable table">
      <caption><strong>POSIX standard <code class="parameter">idtype</code> and <code class="parameter">id</code> arguments</strong></caption>
      
       <tbody class="tbody">
        <tr>
         <td>If <code class="parameter">idtype</code> is <code class="literal">P_ALL</code></td>
         <td>
          wait for any child process, <code class="parameter">id</code> is ignored.
         </td>
        </tr>

        <tr>
         <td>If <code class="parameter">idtype</code> is <code class="literal">P_PID</code></td>
         <td>
          wait for the child with process ID equal to <code class="parameter">id</code>.
         </td>
        </tr>

        <tr>
         <td>If <code class="parameter">idtype</code> is <code class="literal">P_PGID</code></td>
         <td>
          wait for any child with process group ID equal to <code class="parameter">id</code>.
         </td>
        </tr>

       </tbody>
      
     </table>

     <table class="doctable table">
      <caption><strong>Linux specific <code class="parameter">idtype</code> and <code class="parameter">id</code> arguments</strong></caption>
      
       <tbody class="tbody">
        <tr>
         <td>If <code class="parameter">idtype</code> is <code class="literal">P_PIDFD</code> (since Linux 5.4)</td>
         <td>
          wait for the child referred to by the PID file descriptor specified in
          <code class="parameter">id</code>.
          (See the Linux <code class="literal">pidfd_open(2)</code> man page for further
          information on PID file descriptors.)
         </td>
        </tr>

       </tbody>
      
     </table>

     <table class="doctable table">
      <caption><strong>NetBSD and FreeBSD specific <code class="parameter">idtype</code> and <code class="parameter">id</code> arguments</strong></caption>
      
       <tbody class="tbody">
        <tr>
         <td>
          If <code class="parameter">idtype</code> is <code class="literal">P_UID</code>
         </td>
         <td>
          wait for processes whose effective user ID is equal to
          <code class="parameter">id</code>.
         </td>
        </tr>

        <tr>
         <td>
          If <code class="parameter">idtype</code> is <code class="literal">P_GID</code>
         </td>
         <td>
          wait for processes whose effective group ID is equal to
          <code class="parameter">id</code>.
         </td>
        </tr>

        <tr>
         <td>
          If <code class="parameter">idtype</code> is <code class="literal">P_SID</code>
         </td>
         <td>
          wait for processes whose session ID is equal to
          <code class="parameter">id</code>.
          If the child process started its own session, its session ID will be
          the same as its process ID. Otherwise the session ID of a child
          process will match the caller&#039;s session ID.
         </td>
        </tr>

       </tbody>
      
     </table>

     <table class="doctable table">
      <caption><strong>FreeBSD specific <code class="parameter">idtype</code> and <code class="parameter">id</code> arguments</strong></caption>
      
       <tbody class="tbody">
        <tr>
         <td>
          If <code class="parameter">idtype</code> is <code class="literal">P_JAILID</code>
         </td>
         <td>
          wait for processes within a jail whose jail identifier is equal to
          <code class="parameter">id</code>.
         </td>
        </tr>

       </tbody>
      
     </table>

    </dd>
   
   
    <dt><code class="parameter">info</code></dt>
    <dd>
     <p class="para">
      The <code class="parameter">info</code> parameter is set to an array
      containing information about the signal.
     </p>
     <p class="para">
      <code class="parameter">info</code> array may contain the following keys:
      <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">
      The value of <code class="parameter">flags</code> is the value of zero or more of
      the following constants OR&#039;ed together:
      <table class="doctable table">
       <caption><strong>possible values for <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>
           Status shall be returned for any continued child process whose
           status either has not been reported since it continued from a job
           control stop or has been reported only by calls to
           <span class="function"><strong>pcntl_waitid()</strong></span> with the
           <strong><code><a href="pcntl.constants.php#constant.wnowait">WNOWAIT</a></code></strong> flag set.
          </td>
         </tr>

         <tr>
          <td><strong><code><a href="pcntl.constants.php#constant.wexited">WEXITED</a></code></strong></td>
          <td>
           Wait for processes that have exited.
          </td>
         </tr>

         <tr>
          <td><strong><code><a href="pcntl.constants.php#constant.wnohang">WNOHANG</a></code></strong></td>
          <td>
           Do not hang if no status is available; return immediately.
          </td>
         </tr>

         <tr>
          <td><strong><code><a href="pcntl.constants.php#constant.wnowait">WNOWAIT</a></code></strong></td>
          <td>
           Keep the process whose status is returned in
           <code class="parameter">info</code> in a waitable state. This shall not
           affect the state of the process; the process may be waited for again
           after this call completes.
          </td>
         </tr>

         <tr>
          <td><strong><code><a href="pcntl.constants.php#constant.wstopped">WSTOPPED</a></code></strong></td>
          <td>
           Status shall be returned for any child that has stopped upon receipt
           of a signal, and whose status either has not been reported since it
           stopped or has been reported only by calls to
           <span class="function"><strong>pcntl_waitid()</strong></span> with the
           <strong><code><a href="pcntl.constants.php#constant.wnowait">WNOWAIT</a></code></strong> flag set.
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>
   
   
    <dt><code class="parameter">resource_usage</code></dt>
    <dd>
     <p class="simpara">
      The <code class="parameter">resource_usage</code> parameter is set to an
      associative <span class="type"><a href="language.types.array.php" class="type array">array</a></span> containing resource usage statistics
      from the child process. For information on the contents see
      <span class="function"><a href="function.getrusage.php" class="function">getrusage()</a></span>.
     </p>
     <p class="simpara">
      This is only supported if the <code class="literal">wait6(2)</code> system call is
      available, for example on FreeBSD, or on Linux through the raw
      <code class="literal">waitid(2)</code> system call; otherwise the parameter is
      left untouched.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pcntl-waitid-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   <span class="function"><strong>pcntl_waitid()</strong></span> returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> if
   <strong><code><a href="pcntl.constants.php#constant.wnohang">WNOHANG</a></code></strong> was specified and status is not available for
   any process specified by <code class="parameter">idtype</code> and
   <code class="parameter">id</code>.
  </p>

  <p class="para">
   <span class="function"><strong>pcntl_waitid()</strong></span> returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> due to the change of state
   of one of its children.
  </p>

  <p class="para">
   Otherwise, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned and <span class="function"><a href="function.pcntl-get-last-error.php" class="function">pcntl_get_last_error()</a></span>
   can be used to get the <code class="literal">errno</code> error number.
  </p>

  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    Once an <code class="literal">errno</code> error number has been obtained,
    <span class="function"><a href="function.pcntl-strerror.php" class="function">pcntl_strerror()</a></span> can be used to get the text message
    associated with it.
   </p>
  </p></blockquote>
 </div>


  <div class="refsect1 errors" id="refsect1-function.pcntl-waitid-errors">
  <h3 class="title">Помилки/виключення</h3>
  <table class="doctable table">
   <caption><strong>Error number (<code class="literal">errno</code>) values</strong></caption>
   
    <tbody class="tbody">
     <tr>
      <td><strong><code>ECHILD</code></strong></td>
      <td>
       The calling process has no existing unwaited-for child processes.
      </td>
     </tr>

     <tr>
      <td><strong><code>EINTR</code></strong></td>
      <td>
       <span class="function"><strong>pcntl_waitid()</strong></span> was interrupted by a signal.
      </td>
     </tr>

     <tr>
      <td><strong><code>EINVAL</code></strong></td>
      <td>
       An invalid value was specified for <code class="parameter">flags</code>, or
       <code class="parameter">idtype</code> and <code class="parameter">id</code> specify an
       invalid set of processes.
      </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> was added.
      </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> - Waits on or returns the status of a forked child</span></li>
    <li><span class="function"><a href="function.pcntl-wait.php" class="function" rel="rdfs-seeAlso">pcntl_wait()</a> - Waits on or returns the status of a forked child</span></li>
    <li><span class="function"><a href="function.pcntl-fork.php" class="function" rel="rdfs-seeAlso">pcntl_fork()</a> - Forks the currently running process</span></li>
    <li><span class="function"><a href="function.pcntl-signal.php" class="function" rel="rdfs-seeAlso">pcntl_signal()</a> - Installs a signal handler</span></li>
    <li><span class="function"><a href="function.pcntl-wifexited.php" class="function" rel="rdfs-seeAlso">pcntl_wifexited()</a> - Checks if status code represents a normal exit</span></li>
    <li><span class="function"><a href="function.pcntl-wifstopped.php" class="function" rel="rdfs-seeAlso">pcntl_wifstopped()</a> - Checks whether the child process is currently stopped</span></li>
    <li><span class="function"><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</span></li>
    <li><span class="function"><a href="function.pcntl-wexitstatus.php" class="function" rel="rdfs-seeAlso">pcntl_wexitstatus()</a> - Returns the return code of a terminated child</span></li>
    <li><span class="function"><a href="function.pcntl-wtermsig.php" class="function" rel="rdfs-seeAlso">pcntl_wtermsig()</a> - Returns the signal which caused the child to terminate</span></li>
    <li><span class="function"><a href="function.pcntl-wstopsig.php" class="function" rel="rdfs-seeAlso">pcntl_wstopsig()</a> - Returns the signal which caused the child to stop</span></li>
   </ul>
  </p>
 </div>


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