CakeFest 2024: The Official CakePHP Conference

pcntl_getpriority

(PHP 5, PHP 7, PHP 8)

pcntl_getpriorityプロセスの優先度を取得する

説明

pcntl_getpriority(?int $process_id = null, int $mode = PRIO_PROCESS): int|false

pcntl_getpriority() は、 process_id の優先度を設定します。システムの型やカーネルの バージョンによって優先度の扱いは違うので、詳細についてはシステムの getpriority(2) の man ページを参照ください。

パラメータ

process_id

null だった場合は、現在のプロセスの プロセスID を使用します。

mode

PRIO_PGRPPRIO_USERPRIO_PROCESSPRIO_DARWIN_BGPRIO_DARWIN_THREAD のいずれか。

戻り値

pcntl_getpriority() はプロセスの優先度を返します。 エラー時には false を返します。数字が小さいほど、優先順位は上となります。

警告

この関数は論理値 false を返す可能性がありますが、false として評価される値を返す可能性もあります。 詳細については 論理値の セクションを参照してください。この関数の返り値を調べるには ===演算子 を 使用してください。

変更履歴

バージョン 説明
8.0.0 process_id は、nullable になりました。

参考

add a note

User Contributed Notes 1 note

up
2
jonathan at jcdesigns dot com
15 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);
}
To Top