linux看护进程脚本
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"
相关推荐
linuxwcj 2020-10-21
彼岸随笔 2020-10-20
yutou0 2020-10-17
jarrygao 2020-11-02
shipinsky 2020-09-23
touchfuture 2020-09-16
hongsheyoumo 2020-09-04
momoku 2020-09-11
ruancw 2020-08-27
TuxedoLinux 2020-08-18
vvu 2020-08-16
downtown 2020-08-11
luvzhan 2020-07-28
maxelliot 2020-06-28
cuixingwudi 2020-06-25
linuxdashencom 2020-06-21
旭灿 2020-06-16
wenjieyatou 2020-06-14