进程

PHP监控一个进程是否在运行的方法

PHP监控一个进程是否在运行的方法

 

exec("pgrep lighttpd", $pids);
if(empty($pids)) {

    // lighttpd is not running!
}

pgrep -f  全名匹配.

 

$mabbitmq=shell_exec("pgrep [r]abbitmq"); //https://stackoverflow.com/questions/51551908/why-is-the-result-equal-to-0-and-sometimes-1-shell-execpgrep-f
$mabbitmq = str_replace(PHP_EOL, '', $mabbitmq);
$mongodb=shell_exec("pgrep [m]ongo");
$mongodb = str_replace(PHP_EOL, '', $mongodb);
$ydmcuclient=shell_exec("pgrep -f [y]dmcu_client");
$ydmcuclient