进程监控

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

  1 #! /bin/bash
  2 
  3 CodeName=test1.sh
  4 APP_PATH=/home/sram/shellfile/$CodeName
  5 
  6 while [ 1 ] ;do
  7 PID=`ps -ef|grep "$CodeName"|grep -v "grep" |wc -l`
  8 if [ $PID -eq 0 ] ;then
  9   echo "PID=$PID"
 10   echo "false!"
 11   cd $(dirname $APP_PATH)
 12   $APP_PATH &
 13 elif [ $PID -gt 1 ] ;then
 14   echo "PID=$PID"
 15   killall -9 $CodeName
 16   cd $(dirname $APP_PATH)
 17   $APP_PATH &
 18 else
 19   echo "PID=$PID"
 20   echo "true!"
 21 fi
 22 sleep 10
 23 done