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);
}
pcntl_getpriority
(PHP 5)
pcntl_getpriority — Bir sürecin önceliğini döndürür
Açıklama
$pid = getmypid()
[, int $süreç_türü = PRIO_PROCESS
]] )
pid ile belirtilen sürecin öncelik seviyesini
döndürür. Öncelik seviyeleri sistem türüne ve çekirdeğe göre farklılık
gösterdiğinden ayrıntılı bilgi için sisteminizdeki setpriority(2) kılavuz
sayfasına bakınız.
Değiştirgeler
-
pid -
Belirtilmezse işlevi çağıran sürecin süreç kimliği kullanılır.
-
süreç_türü -
PRIO_PGRP,PRIO_USERvePRIO_PROCESSsabitlerinden biri.
Dönen Değerler
Hata durumunda FALSE yoksa belirtilen sürecin öncelik seviyesini
döndürür. Düşük sayısal değerler daha yüksek öncelik sağlar.
Bu işlev mantıksal FALSE
değeriyle dönebileceği gibi FALSE olarak değerlendirilebilecek mantıksal
olmayan bir değerle de dönebilir. Bu konuda daha fazla bilgi edinmek için
Mantıksal Değerler bölümüne
bakabilirsiniz. Bu işlevden dönen değeri sınamak için
===
işlecini kullanınız.
