进程监控脚本程序

来源:互联网 发布:网络解锁助手1.0.9 编辑:程序博客网 时间:2024/06/02 07:30

脚本名demo.sh

#!/bin/sh

echo "$#"
while [ 1 ]
do

pidof $1
if [ $? != 0 ]
then
    echo "$1 is not run! Now begin to run..."
    ./hello1 & #监控的应用程序 路径
else
    echo "$1 is running."
fi
pidof $2
if [ $? != 0 ]
then
    echo "$2 is not run! Now begin to run..."
    ./hello2 & #监控的应用程序 路径
else
    echo "$2 is running."
fi
sleep 5
done

 

使用的时候:./demo.sh hello1 hello2

后面跟的参数就是你要监控的进程的名字(程序可执行文件的名字)
0 0