大网数据广告活动
PHP 语言与运行手册

pcntl_rfork · Manipulates process resources

· 52CE 我爱测

flags The flags parameter determines which resources of the invoking process (parent) are shared by the new process (child) or initialized to their default values.

pcntl_rfork

(PHP 8 >= 8.1.0)

pcntl_rfork — Manipulates process resources

说明

function pcntl_rfork(int $flags, int $signal = 0): int

Manipulates process resources.

参数

flags

The flags parameter determines which resources of the invoking process (parent) are shared by the new process (child) or initialized to their default values.

flags is the logical OR of some subset of:

  • RFPROC: If set a new process is created; otherwise changes affect the current process.
  • RFNOWAIT: If set, the child process will be dissociated from the parent. Upon exit the child will not leave a status for the parent to collect.
  • RFFDG: If set, the invoker's file descriptor table is copied; otherwise the two processes share a single table.
  • RFCFDG: If set, the new process starts with a clean file descriptor table. Is mutually exclusive with RFFDG.
  • RFLINUXTHPN: If set, the kernel will return SIGUSR1 instead of SIGCHLD upon thread exit for the child. This is intended to do Linux clone exit parent notification.
  • RFTSIGZMB: If set, the kernel will deliver the signal specified by the signal parameter to the parent upon the child exit, instead of the default SIGCHLD. Specifying signal number 0 disables signal delivery upon the child exit.
  • RFTHREAD: If set, the new process shares file descriptor to process leaders table with its parent. Only applies when neither RFFDG nor RFCFDG are set.
signal

The signal number to deliver to the parent when the child exits. This is only used when the RFTSIGZMB flag is set. Specifying 0 disables signal delivery upon the child exit.

返回值

On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. On failure, a -1 will be returned in the parent's context, no child process will be created, and a PHP error is raised.

示例

示例 #1 pcntl_rfork() example

<?php

$pid = pcntl_rfork(RFNOWAIT|RFTSIGZMB, SIGUSR1);
if ($pid > 0) {
  // This is the parent process.
  var_dump($pid);
} else {
  // This is the child process.
  var_dump($pid);
  sleep(2); // as the child does not wait, so we see its "pid"
}
?>

以上示例的输出类似于:

int(77093)
int(0)

注释

注意:

This function is only available on BSD systems.

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。