Linux Shell

Linux守护进程🙅‍♀️

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#!/bin/bash
# nohup.sh
while true
do 
    # -f 后跟进程名,判断进程是否正在运行
    if [ `pgrep -f <ProcessName> | wc -l` -eq 0 ];then
        echo "进程已终止"
        push
        # /dev/null 无输出日志
        nohup ./<ProcessName> > /dev/null 2>&1 &
    else
        echo "进程正在运行"
    fi
    # 每隔1分钟检查一次
    sleep 1m
done    
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy