<?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-rfork.php',
    1 => 'pcntl_rfork',
    2 => 'プロセスのリソースを管理する',
  ),
  'up' => 
  array (
    0 => 'ref.pcntl.php',
    1 => 'PCNTL 関数',
  ),
  'prev' => 
  array (
    0 => 'function.pcntl-getqos-class.php',
    1 => 'pcntl_getqos_class',
  ),
  'next' => 
  array (
    0 => 'function.pcntl-setcpuaffinity.php',
    1 => 'pcntl_setcpuaffinity',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/pcntl/functions/pcntl-rfork.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pcntl-rfork" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pcntl_rfork</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.1.0)</p><p class="refpurpose"><span class="refname">pcntl_rfork</span> &mdash; <span class="dc-title">プロセスのリソースを管理する</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.pcntl-rfork-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pcntl_rfork</strong></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>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$signal</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   プロセスのリソースを管理します。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pcntl-rfork-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">flags</code> は、
       呼び出しているプロセス(親) のリソースを新しいプロセス(子)と共有するか、
       デフォルト値で初期化するかを指定します。
      </p>
      <p class="para">
       <code class="parameter">flags</code> は、
       以下のうちのいくつかを論理ORで指定します:
       <ul class="simplelist">
        <li>
         <strong><code><a href="pcntl.constants.php#constant.rfproc">RFPROC</a></code></strong>:
         設定すると、新しいプロセスが作られます。
         設定しない場合、変更は現在のプロセスに適用されます。
        </li>
        <li>
         <strong><code><a href="pcntl.constants.php#constant.rfnowait">RFNOWAIT</a></code></strong>:
         設定すると、子プロセスは親プロセスから切り離されます。
         子プロセスが終了するときには、
         親プロセスが収集するステータスが残りません。
        </li>
        <li>
         <strong><code><a href="pcntl.constants.php#constant.rffdg">RFFDG</a></code></strong>:
         設定すると、
         呼び出し側のファイルディスクリプタテーブルがコピーされます。
         設定しない場合、
         ふたつのプロセスが単一のテーブルを共有します。
        </li>
        <li>
         <strong><code><a href="pcntl.constants.php#constant.rfcfdg">RFCFDG</a></code></strong>:
         設定すると、新しいファイルディスクリプタテーブルを使って
         新しいプロセスが開始されます。
         <strong><code><a href="pcntl.constants.php#constant.rffdg">RFFDG</a></code></strong> とは同時に指定できません。
        </li>
        <li>
         <strong><code><a href="pcntl.constants.php#constant.rflinuxthpn">RFLINUXTHPN</a></code></strong>:
         設定すると、
         子のスレッドが終了時に kernel は SIGCHILD ではなく、
         SIGUSR1 を返します。
         これは、Linux のcloneが終了時に、
         親に状態を知らせる動作を模倣する意図があります。
        </li>
       </ul>
      </p>
     </dd>
    
    
     <dt><code class="parameter">signal</code></dt>
     <dd>
      <p class="para">
       シグナル番号
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pcntl-rfork-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   成功時には、親スレッドの実行時に子プロセスのPIDを返し、
   子のスレッド実行時に <code class="literal">0</code> を返します。
   失敗時には、親のコンテキストには <code class="literal">-1</code> を返し、
   子プロセスは作られません。そして、PHP のエラーが発生します。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.pcntl-rfork-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>pcntl_rfork()</strong></span> の例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$pid </span><span style="color: #007700">= </span><span style="color: #0000BB">pcntl_rfork</span><span style="color: #007700">(</span><span style="color: #0000BB">RFNOWAIT</span><span style="color: #007700">|</span><span style="color: #0000BB">RFTSIGZMB</span><span style="color: #007700">, </span><span style="color: #0000BB">SIGUSR1</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$pid </span><span style="color: #007700">&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />  </span><span style="color: #FF8000">// This is the parent process.<br />  </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$pid</span><span style="color: #007700">);<br />} else {<br />  </span><span style="color: #FF8000">// This is the child process.<br />  </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$pid</span><span style="color: #007700">);<br />  </span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">); </span><span style="color: #FF8000">// as the child does not wait, so we see its "pid"<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>上の例の出力は、
たとえば以下のようになります。</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">int(77093)
int(0)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.pcntl-rfork-notes">
  <h3 class="title">注意</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    この関数は、BSDシステムでのみ利用可能です。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pcntl-rfork-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-waitpid.php" class="function" rel="rdfs-seeAlso">pcntl_waitpid()</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.cli-set-process-title.php" class="function" rel="rdfs-seeAlso">cli_set_process_title()</a> - プロセスのタイトルを設定する</span></li>
   </ul>
  </p>
 </div>


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