How to check whether specified PID is currently running without invoking ps from PHP?

后端 未结 9 1861
时光说笑
时光说笑 2020-12-15 03:29

We would like to check if a specified process is currently running via PHP.

We would like to simply supply a PID and see if it is currently executing or not.

相关标签:
9条回答
  • 2020-12-15 04:12

    Here is how we do it:

    if (`ps -p {$pid} -o comm,args=ARGS | grep php`) {
    
      //process with pid=$pid is running;
    }
    
    0 讨论(0)
  • 2020-12-15 04:19

    I would call a bash script using shell_exec

    $pid = 23818;
    if (shell_exec("ps aux | grep " . $pid . " | wc -l") > 0)
    {
        // do something
    }
    
    0 讨论(0)
  • 2020-12-15 04:24

    posix_getpgid($pid); will return false when a process is not running

    0 讨论(0)
提交回复
热议问题