linux如何让一个程序崩溃后自动重启

思路:  写一个脚本 监控程序的运行状态  没有运行启动运行 已运行不做操作。

如果在控制台启动脚本 注意必须  nohup sh xxx.sh &

while true
do
    ps -ef | grep "填入你自己的程序名" | grep -v "grep"
    if [ "$?" -eq 1 ]
        then
        ./run.sh #启动应用,修改成自己的启动应用脚本或命令
        echo "process has been restarted!"
    else
        echo "process already started!"
    fi
    sleep 10
done

while :
do
    cd /xxx
    ulimit -n 819200
    stillRunning=$(ps -ef |grep "填入你自己的程序名" |grep -v "grep")
    
    if [ "$stillRunning" ] ; then
        sleep 1
    else
        echo "starting  填入你自己的程序名 process ...."
        ./run.sh #启动应用,修改成自己的启动应用脚本或命令
        sleep 2
    fi
done

猜你喜欢

转载自www.cnblogs.com/swing07/p/10563453.html