<?php
if(1){
$class_name = preg_quote('/var/spool/clientm', '/');
$file_name = preg_quote('/var/run/ntpd.pid', '/');
} else {
$class_name = 'Test_Batch';
$file_name = preg_quote('./batch.php', '/');
}
$result = shell_exec('ps ax');
$process_list = explode("\n", trim($result));
$match_cnt = 0;
foreach($process_list as $k => $ps){
if($k == 0){
continue;
}
foreach(array($class_name, $file_name) as $name){
if(preg_match("/^.*[\s]+{$name}(.*)$/", $ps, $match)){
if(strlen($match[1]) && strpos($match[1], ' ') !== 0){
continue;
}
echo "**** match $ps ****\n";
$match_cnt++;
}
}
}
if($match_cnt >= 2){
echo "**** dup ****\n";
}