PCNTL 函数
在线手册:中文  英文

pcntl_getpriority

(PHP 5)

pcntl_getpriority获取任意进程的优先级

说明

int pcntl_getpriority ([ int $pid = getmypid() [, int $process_identifier = PRIO_PROCESS ]] )

pcntl_getpriority() 获取进程号为 pid的进程的优先级。由于不同的系统类型以及内核版本下 优先级可能不同,因此请参考您系统的getpriority(2)手册以获取详细的规范。

参数

pid

如果没有指定,默认是当前进程的进程号。

process_identifier

PRIO_PGRP(译注:获取进程组优先级), PRIO_USER (译注:获取用户进程优先级)或 PRIO_PROCESS(译注:默认值;获取进程优先级)三者之一。

返回值

pcntl_getpriority() 返回进程的优先级或在错误时返回 FALSE 。 值越小代表优先级越高。

Warning

此函数可能返回布尔值 FALSE,但也可能返回等同于 FALSE 的非布尔值。请阅读 布尔类型章节以获取更多信息。应使用 === 运算符来测试此函数的返回值。

参见


PCNTL 函数
在线手册:中文  英文

用户评论:

jonathan at jcdesigns dot com (2008-05-15 02:12:47)

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);
}

易百教程