I am using kannel to send SMS via PHP. I want to know how can I check if a particular process is running. For kannel to run, a process named bearerbox
should be running all time. I want to check if this process is running or not. Because if the process is not running then a mail will be sent to me notifying me about it.
In PHP this can be retrieved using getmypid() which will return an integer number. This pid number can be saved to a file and each time the script is run a check made to see if the file exists. If it is the posix_kill() function can be used to see if a process is running with that pid number.
Determining if a PHP function is available You can determine whether or not a PHP function is enabled for your web site by using the function_exists() function.
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.
The easiest is to use pgrep
, which has an exit code of 0 if the process exists, 1 otherwise.
Here's an example.
exec("pgrep bearerbox", $output, $return);
if ($return == 0) {
echo "Ok, process is running\n";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With