I needed to write a small function, that can check if a specific PID is running an linux/unix system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php
/**
* Checks if a process is running using 'exec(ps $pid)'.
* @author Julius Beckmann
* @param PID of Process
* @return Boolean true == running
*/
protected function isPidRunning($pid) {
$lines_out = array();
exec('ps '.(int)$pid, $lines_out);
if(count($lines_out) >= 2) {
// Process is running
return true;
}
return false;
} |
Check it out on Gist: https://gist.github.com/3096556