shell杀死指定进程

来源:互联网 发布:旱雪 知乎 编辑:程序博客网 时间:2024/05/16 09:43
#!/bin/bash#!/bin/sh#根据进程名杀死进程if [ $# -lt 1 ]then  echo "缺少参数:procedure_name"  exit 1fi PROCESS=`ps -ef|grep $1|grep -v grep|grep -v PPID|awk '{ print $2}'`for i in $PROCESSdo  echo "Kill the $1 process [ $i ]"  kill -9 $idone
#!/bin/bashcd /home/nodejs/nodejs-imnohup nodejs app.js > mylog.log 2>&1 &cd /home/nodejs/nodejs-im-common/websocketnohup nodejs app.js > mylog.log 2>&1 &
</pre><pre code_snippet_id="1962125" snippet_file_name="blog_20161102_2_4446445" name="code" class="plain">检测进程是否存在


#!/bin/sh   pid=`ps -ef | grep -v grep | grep -v "test.sh" | grep $1 | sed -n  '1P' | awk '{print $2}'`  if [ -z $pid ] ; then      echo "no this process"  else      echo $pid  fi  

每隔5秒判断进程是否死掉,死掉就在起来

#!/bin/shwhile true;do    count=`ps -ef|grep nodejs|grep -v grep`    if [ "$?" -lt 2 ];thenecho  "nodejs...run it"cd /home/nodejs/nodejs-im-common/websocketnohup nodejs app.js > mylog.log 2>&1 &elseecho ">>>>nodejs is runing..."fisleep 5done


0 0
原创粉丝点击