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

anonymous-one picture anonymous-one · Mar 26, 2012 · Viewed 41.5k times · Source

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.

Does PHP have an internal function that would give us this information or do we have to parse it out of "ps" output?

Answer

Nasreddine picture Nasreddine · Mar 26, 2012

If you are on Linux, try this :

if (file_exists( "/proc/$pid" )){
    //process with a pid = $pid is running
}