一个短小精悍的监控/守护进程

来源:互联网 发布:互联网金融 创业 知乎 编辑:程序博客网 时间:2024/05/22 19:56

一个短小精悍的监控/守护进程

  • Author: 柳大·Poechant(钟超)
  • Email: zhongchao.ustc#gmail.com
  • Blog: Blog.CSDN.net/Poechant
  • Date: May 28th, 2012
#!/bin/bashYOUR_TARGET = your_targetwhile: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 10done
  • grep -v: –invert-match. Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)

-

转载请注明来自柳大的CSDN博客:Blog.CSDN.net/Poechant

-

原创粉丝点击