1. 看護進程腳本。工作原理是用shell不停的去查詢進程,如果發現進程不存在則啓動進程。如果用gnome啓動,要在圖形界面啓動腳本。
start.sh
#! /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.sh
#! /bin/bash ./start.sh &
3. 關閉啓動進程腳本。
bhstop.sh
#!/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"