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

时间:2023-03-08 20:08:19
linux如何让一个程序崩溃后自动重启

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

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

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

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