linux脚本判断进程不在就重启进程,Linux下检测程序进程是否正常并重启的脚本...

#!/bin/sh

#set program name

ProgramFile=WDWifiDetector

#----------------------------------------------The following contents are prohibited to modify by the user-------------------------------------------

while((1>0))

do

pid=$(pgrep $ProgramFile)

echo $ProgramFile pid=$pid

#pgrep $ProgramFile>/dev/null:检测进程是否存在

#echo $pid|grep -c ' '>/dev/null:检测进程的个数,如果程序中用了诸如fork等函数启动了额外的进程,则需要检#测进程的个数,$pid中进程号和进程号是空格隔开,用grep统计空格个数;如果只有一个进程则下面的if不需要此判断

if (pgrep $ProgramFile>/dev/null) && (echo $pid|grep -c ' '>/dev/null)

then

echo $ProgramFile progress is exist!

else

echo $ProgramFile progress is not exist or incomplete.Ready to launch the program......

pgrep $ProgramFile|xargs kill -s 9

sleep 60

$ProgramFile &

echo $ProgramFile is launched.....

fi

sleep 10

done

exit 0

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值