mrkeck Sharing the Love

21Jun/160

Linux See if Process including Argument is Running

Problem I had was when run.php 13 was running it also thought run.php 1 was also running since the 13 contains 1.
Look for only processes run by root and ends with the argument matching the id

$file = '/var/www/html/run.php 1';
$isRunning = array();
exec('ps aux | grep "' . $file . '"', $isRunning);
$run = true;
    foreach($isRunning as $process){
        if( substr($process, 0, 4) == 'root'){
             $lastPart = array_pop(explode(' ', $process));
             //echo $lastPart;
           if( $lastPart == $sites[$i]['id'] ){
              $run = false;
           }
         }
     }
Filed under: EC2 Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.