linux看護進程指令碼

來源:互聯網
上載者:User

linux看護進程指令碼 1. 看護進程指令碼。工作原理是用shell不停的去查詢進程,如果發現進程不存在則啟動進程。如果用gnome啟動,要在圖形介面啟動指令碼。start.sh Js代碼  #! /bin/bash  #program directory path  PRO_PATH="/opt/bin/"  #program name  PRO_NAME="Record"  #program path, not need configure.  PRO_MAIN=$PRO_PATH$PRO_NAME  #GNOME start program, not need configure.  PROGRAM_GNOME="gnome-terminal -e \"$PRO_MAIN\""  #start  method  GNOME or nohup (eg: GNONE-->STAR_PRO=$PROGRAM_GNOME ; nohup-->STAR_METHOD=$PRO_MAIN)  STAR_METHOD=$PROGRAM_GNOME      while true ; do      PRO_NOW=`ps aux | grep $PRO_NAME | grep -v grep | wc -l`      if [ $PRO_NOW -lt 1 ]; then               $STAR_METHOD 2>/dev/null 1>&2 &         date >> $PRO_PATH/tinfo.log           echo "------------------$PRO_MAIN start----------------------" >> $PRO_PATH/tinfo.log      fi  sleep 10  done  exit 0   2. 啟動進程指令碼。如果用用戶端直接啟動start.sh,關掉用戶端啟動的程式會死掉。用這個進程啟動後,關掉用戶端,進程依然存在。bhstart.shJs代碼  #! /bin/bash  ./start.sh &    3. 關閉啟動進程指令碼。bhstop.shJava代碼  #!/bin/bash  #progress name  PRO_NAME="Record"    ps -ef|grep $PRO_NAME |grep -v grep|awk '{print $3}'|xargs kill  echo "kill start.sh done!"  ps -ef|grep $PRO_NAME |grep -v grep|awk '{print $2}'|xargs kill  echo "kill $PRO_NAME done"  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.