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)
{
$first = substr($scriptName, 0, 1);
$rest = substr($scriptName, 1);
$name = '"['.$first.']'.$rest.'"';
$cmd = "ps aux | grep $name | wc -l";
$result = exec($cmd);
return $result;
}
?>