Linux开发之守护进程

来源:互联网 发布:淘宝开店注册在哪里 编辑:程序博客网 时间:2024/05/03 08:11
#!/bin/sh
defender_pid=`ps aux|grep -v 'grep'|grep -c '/指定的程序名'`
#echo "$defender_pid"
if [ $defender_pid -eq 0 ]

then

#获取当前所在目录,也可以直接指定目录

dir=$(cd "$(dirname "$0")"; pwd)

cd $dir

#执行需要守护的程序

./你的程序

nohup ./你的程序 >/dev/null 2>&1 &
cd /home/
now=`date  +%Y-%m-%d[%H:%M:%S]`
echo "at $now start 你的程序 -b \n"
fi
0 0
原创粉丝点击