开发者

Checking for an active process in linux

开发者 https://www.devze.com 2023-01-31 23:54 出处:网络
I\'ve got a rather buggy开发者_如何学运维 version of php-fpm (ubuntu) running, I\'m looking for a script (which will be run as cronjob).. that check if php5-fpm is running, and if its not.. to re-exec

I've got a rather buggy开发者_如何学运维 version of php-fpm (ubuntu) running, I'm looking for a script (which will be run as cronjob).. that check if php5-fpm is running, and if its not.. to re-execute it.


You can check if a process is running using the pgrep command.

victor:~$ pgrep bash
5554
victor:~$ 

As you can see, it returns the process ID of all matching processes.


You may use the ps command to detect running processes and grep for the 'php-pfm' application - could be looking like that:

TEST=`ps -faxu |grep 'php-pfm'|grep -v 'grep'`
if [ -e  "$TEST" ]; then
    #not running... restart!
    php-fpm &
fi

You may try the man pages for 'ps' and 'grep'...

Edit: new code fragment including victors fix:

TEST=`ps -faxu |grep 'php-pfm'|grep -v 'grep'`
if [ -z  "$TEST" ]; then
    #not running... restart!
    php-fpm &
fi

-- Mayday

0

精彩评论

暂无评论...
验证码 换一张
取 消