在项目中,如果应用程序崩溃了,我们想把程序重新启动,该怎么做呢?
linux下,可以写一个shell脚本:
#!/bin/bash
while true
do
ps -ef | grep "test" | grep -v grep
if [ "$?" -eq 1 ]
then
./test
echo "restarted!"
else
echo "already started"
fi
sleep 10
done
windows下,可以写一个bat文件,循环查看应用程序是否还在:
:loop
ping -n 5 127.0.0.1
tasklist|find /i "test.exe"
if %errorlevel%==1 (
start "" "./test.exe"
)
goto :loop
网友评论