实现过程:每个一秒ps一次进程是否存在,不存在则nohup启动之。
用法:autostart "test 1"
autostart()
{
if [ $# -eq 0 ]
then
echo "usage: autostart \"test 1\""
echo
return
fi
while [ 1 ]
do
ps -ef |grep -w "$1" |grep -w `whoami`|grep -vw grep|grep -vw tail
if [ $? -ne 0 ]
then echo "start process....."
nohup $1 >/dev/null &
else
echo "runing....."
fi
sleep 1
done
}
本文介绍了一个简单的bash脚本,用于自动检测指定进程是否运行,若未运行则使用nohup命令自动启动该进程。此脚本适用于后台服务监控及自动重启场景。
1342

被折叠的 条评论
为什么被折叠?



