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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM