一个短小精悍的监控/守护进程
- Author: 柳大·Poechant(钟超)
- Email: zhongchao.ustc#gmail.com
- Blog: Blog.CSDN.net/Poechant
- Date: May 28th, 2012
#!/bin/bash
YOUR_TARGET = your_target
while:
do
echo "Current DIR is " $PWD
stillRunning = $(ps -ef | grep "$PWD/$YOUR_TARGET" | grep -v "grep")
if [ "$stillRunning" ]; then
echo "You target service was already started by another way"
echo "Kill it and then startup by this shell, otherwise this shell will loop out this message annoyingly"
kill -9 $pidof $PWD/$YOUR_TARGET
else
echo "Your target service was not started"
echo "Starting service …"
$PWD/$YOUR_TARGET &
echo "Your target service was exited!"
fi
sleep 10
done
grep -v
: –invert-match. Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)
-
转载请注明来自柳大的CSDN博客:Blog.CSDN.net/Poechant
-