Linux判断进程是否存在并启动该进程

来源:互联网 发布:arena软件下载 编辑:程序博客网 时间:2024/05/30 04:53

Linux判断进程是否存在并启动该进程

1.Linux判断进程是否存在并启动该进程

#!/bin/bash#判断进程是否存在,如果不存在就启动它PIDS=`ps -ef |grep myprocess |grep -v grep | awk '{print $2}'`if [ "$PIDS" != "" ]; thenecho "myprocess is runing!"elsecd /root/./myprocess#运行进程fi

2.linux判断进程是否存在并重启该进程

#!/bin/bash#判断进程是否存在,如果不存在就启动它如果存在就重启它PIDS=`ps -ef |grep myprocess |grep -v grep | awk '{print $2}'`if [ "$PIDS" != "" ]; thenkill -9 $PIDS#先关闭进程,在运行此进程cd /root/myprocesssudo ./myprocess#重新运行进程elsecd /root/myprocesssudo ./myprocess#运行进程fi

最后编辑crontab -e 按需要设置运行时间。


0 0