Checking if process still running?

后端 未结 9 574
野的像风
野的像风 2020-11-30 03:55

As a way to build a poor-man\'s watchdog and make sure an application is restarted in case it crashes (until I figure out why), I need to write a PHP CLI script that will be

9条回答
  •  悲哀的现实
    2020-11-30 04:34

    You can try this, which combines bits of those two approaches:

    function processExists($processName) {
        $exists= false;
        exec("ps -A | grep -i $processName | grep -v grep", $pids);
        if (count($pids) > 0) {
            $exists = true;
        }
        return $exists;
    }
    

    If that doesn't work, you may want to just try running the ps command on your system and seeing what output it gives.

提交回复
热议问题