1. Write a Monitor.sh file as below
#! /bin/sh proc_name="Process_Name" #进程名 proc_num() #查询进程数量 { num=`ps -ef | grep $proc_name | grep -v grep | wc -l` return $num } proc_num number=$? #获取进程数量 if [ $number -eq 0 ] #如果进程数量为0
//or you can remove the number and write as this
//if [ $? == 0 ] then #重新启动服务器,或者扩展其它内容。 cd /your/service/path; ./Process_Name.sh fi
2. Create a cron job
$> crontab -e */1 * * * * sh /root/monitor.sh
3. Start and Check the cron status
service crond start
service crond status