如何实现 start 、stop、status?
1)启动的时候将进程号写入文件,停止的时候读取文件得到进程号;
pstree pid -p | awk -F"[()]" '{for(i=0;i<=NF;i++)if($i~/[0-9]+/)print $i}' |grep -E -v "\{|\(|\["|xargs kill -9
#!/bin/shBASE_HOME=/home/apple/testPID=${BASE_HOME}/.pidstatus(){ echo "==========status=======" status=`ps -p $$` }start() { echo "==========start==========="}stop() { echo "===========stop============" pid=$$ kill_cmd="pstree -p $pid | awk -F \"[()]\" '{for(i=0;i<=NF;i++)if(\$i~/[0-9]+/)print \$i}' |"'grep -v -E "\[|\(|\)|\]"|xargs kill -9' eval ${kill_cmd}}restart() { stop; echo "sleeping........."; sleep 3; start;}case "$1" in 'start') start ;; 'stop') stop ;; 'status') status ;; 'restart') restart ;; *) echo "usage: $0 {start|stop|restart|status}" exit 1 ;; esac