略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: pcntl_sigwaitinfo

2024-04-29

pcntl_sigwaitinfo

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

pcntl_sigwaitinfo等待信号

说明

pcntl_sigwaitinfo(array $set, array &$siginfo = ?): int

pcntl_sigwaitinfo()函数暂停调用脚本的执行直到接收到set 参数中列出的某个信号。只要其中的一个信号已经在等待状态(比如: 通过 pcntl_sigprocmask()函数阻塞), 函数pcntl_sigwaitinfo()就回立刻返回。

参数

set

要等待的信号数组。

siginfo

siginfo是一个输出参数,用来返回信号的信息。

以下元素会为所有信号设置:

  • signo: 信号编号
  • errno: 错误编号
  • code: 信号代码

下面元素可能会为SIGCHLD信号设置:

  • status: 退出的值或信号
  • utime: 用户消耗的时间
  • stime: 系统(内核)消耗的时间
  • pid: 发送进程ID
  • uid: 发送进程的实际用户ID

信号SIGILL, SIGFPE, SIGSEGVSIGBUS 可能会被设置的元素:

  • addr: 发生故障的内存位置

可能会为SIGPOLL 信号设置的元素:

  • band: Band event
  • fd: 文件描述符

返回值

成功时,函数pcntl_sigwaitinfo()返回一个信号编号。

范例

示例 #1 pcntl_sigwaitinfo() example

<?php
echo "Blocking SIGHUP signal\n";
pcntl_sigprocmask(SIG_BLOCK, array(SIGHUP));

echo 
"Sending SIGHUP to self\n";
posix_kill(posix_getpid(), SIGHUP);

echo 
"Waiting for signals\n";
$info = array();
pcntl_sigwaitinfo(array(SIGHUP), $info);
?>

参见

add a noteadd a note

User Contributed Notes 1 note

up
-1
dave at mudsite dot com
5 years ago
This function is not available on platforms that do not implement the underlying C function.  Included in this would be MaxOS[1], and FreeBSD[2]

[1] : http://opensource.apple.com//source/xnu/xnu-1456.1.26/bsd/sys/signal.h

[2] : http://fxr.watson.org/fxr/source/sys/signal.h?v=FREEBSD11

官方地址:https://www.php.net/manual/en/function.pcntl-sigwaitinfo.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3