Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

process

pid

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?

like image 278
anonymous-one Avatar asked Mar 26 '12 14:03

anonymous-one


People also ask

How do you check if a PID is running or not?

The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.

How do I know if a PHP script is running?

Check if a PHP script is already running If you have long running batch processes with PHP that are run by cron and you want to ensure there's only ever one running copy of the script, you can use the functions getmypid() and posix_kill() to check to see if you already have a copy of the process running.


1 Answers

If you are on Linux, try this :

if (file_exists( "/proc/$pid" )){     //process with a pid = $pid is running } 
like image 99
Nasreddine Avatar answered Oct 13 '22 06:10

Nasreddine