1.shell通过一个while-do循环,用ps -ef|grep检查loader进程是否正在运行,如果没有运行,则启动,
这样就保证崩溃挂掉的进程重新被及时启动。
注意2点:1.ps -ef |grep 一个进程时必须加上其路径,否则容易grep到错误的结果;
2.必须用-v 从结果中去除grep命令自身,否则结果非空。
#!/bin/sh
while :
do
echo "Current DIR is " $PWD
stillRunning=$(ps -ef |grep "$PWD/loader" |grep -v "grep")
if [ "$stillRunning" ] ; then
echo "TWS service was already started by another way"
echo "Kill it and then startup by this shell, other wise this shell will loop out this message annoyingly"
kill -9 $pidof $PWD/loader
else
echo "TWS service was not started"
echo "Starting service ..." $PWD/loader
echo "TWS service was exited!"
fi sleep 10
done
如果启动此shell时发现进程以及存在,说明已别的方式启动了进程,那么他会持续提醒找到进程,
解决办法是,只要一经发现是其他方式启动此进程即kill掉(kill -9 $PWD/loader)
arvin_feng