note 107022 modified in function.getmypid by danbrown

From: Date: Tue, 03 Jan 2012 21:52:10 +0000
Subject: note 107022 modified in function.getmypid by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185300@lists.php.net to get a copy of this message
Here is how you'd use exec on a posix system to accomplish counting processes quickly. I want to know how many processes are running with 'update.php' in the command: ps aux|grep "[u]pdate.php"|wc -l (the trick of using [u]pdate.php instead of update.php makes sure that the grep command itself is not matched). Be sure to use quotes in the command, or it won't work either. So, the code: <?php function countProcesses($scriptName) { // ps aux|grep "[u]pdate.php"|wc -l $first = substr($scriptName, 0, 1); $rest = substr($scriptName, 1); $name = '"['.$first.']'.$rest.'"'; $cmd = "ps aux | grep $name | wc -l"; $result = exec($cmd); return $result; } ?> --was-- Here is how you'd use exec on a posix system to accomplish counting processes quickly. I want to know how many processes are running with 'update.php' in the command: ps aux|grep "[u]pdate.php"|wc -l (the trick of using [u]pdate.php instead of update.php makes sure that the grep command itself is not matched). Be sure to use quotes in the command, or it won't work either. So, the code: function countProcesses($scriptName) { // ps aux|grep "[u]pdate.php"|wc -l $first = substr($scriptName, 0, 1); $rest = substr($scriptName, 1); $name = '"['.$first.']'.$rest.'"'; $cmd = "ps aux | grep $name | wc -l"; $result = exec($cmd); return $result; } http://php.net/manual/en/function.getmypid.php

« previous php.notes (#185300) next »