PHP: How to track the created process on Linux

On Linux, to create a process and show the process id we use this command:

nohup THE_COMMAND > /dev/null 2>&1 & echo $!

To check the process id, we use this command

ps -p $pid

To stop a process with pid, we can use this command:

kill $pid

Now, we start to code a PHP script to track the created process:


function processmanage_start($cmd){
    $command = 'nohup '.$cmd.' > /dev/null 2>&1 & echo $!';
    exec($command ,$op);
    return (int)$op[0];

function processmanage_status($pid){
    $command = 'ps -p '.$pid;
    if (!isset($op[1]))return false;
    else return true;

function processmanage_stop($pid){
    $command = 'kill '.$pid;
    if (processmanage_status($pid) == false)return true;
    else return false;

Leave a Reply