检查进程是否在Linux中使用PHP运行 [英] Check if a process is running using PHP in Linux

查看:203
本文介绍了检查进程是否在Linux中使用PHP运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 kannel 通过PHP发送短信.我想知道如何检查特定进程是否正在运行.为了运行 kannel ,应该一直运行名为bearerbox的进程.我想检查此过程是否正在运行.因为如果该进程未运行,则会向我发送一封邮件通知我.

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.

推荐答案

最简单的方法是使用pgrep,如果该进程存在,则退出代码为0,否则为1.

The easiest is to use pgrep, which has an exit code of 0 if the process exists, 1 otherwise.

这是一个例子.

exec("pgrep bearerbox", $output, $return);
if ($return == 0) {
    echo "Ok, process is running\n";
}

这篇关于检查进程是否在Linux中使用PHP运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆