pcntl_getpriority
(PHP 5, PHP 7, PHP 8)
pcntl_getpriority — 获取任意进程的优先级
说明
pcntl_getpriority() 获取进程号为
process_id
的进程的优先级。由于不同的系统类型以及内核版本下
优先级可能不同,因此请参考系统的 getpriority(2)手册以获取详细的规范。
参数
process_id
-
如果为
null
,默认使用当前进程的进程号。 mode
-
PRIO_PGRP
(译注:获取进程组优先级)、PRIO_USER
(译注:获取用户进程优先级)、PRIO_PROCESS(译注:默认值;获取进程优先级)
、PRIO_DARWIN_BG
或PRIO_DARWIN_THREAD
之一。
返回值
pcntl_getpriority() 返回进程的优先级或在错误时返回 false
。值越小代表优先级越高。
更新日志
版本 | 说明 |
---|---|
8.0.0 |
process_id 现在可以为 null。
|
+添加备注
用户贡献的备注 1 note
jonathan at jcdesigns dot com ¶
16 years ago
This function is ideal for checking if a given process is running, I have seen solutions that involve running the system utilites like PS and parsing the answer, which should work fine, but this allows you to check a given PID with a single call
function CheckPID( $PID )
{
// Check if the passed in PID represents a vlaid process in the system
// Returns true if it does
// Turn off non-fatal runtime warning for a moment as we know we
// will get one if the PID does not represent a valid process
$oldErrorLevel = error_reporting(0);
error_reporting( $oldErrorLevel & ~E_WARNING );
$res = pcntl_getpriority($PID);
error_reporting( $oldErrorLevel);
return ! ( $res === false);
}
备份地址:http://www.lvesu.com/blog/php/function.pcntl-getpriority.php