首页 > 系统相关 >《Shell脚本学习 —— 后台检测应用程序运行》

《Shell脚本学习 —— 后台检测应用程序运行》

时间:2022-11-18 15:12:08浏览次数:46  
标签:count Shell 程序运行 media app yd cost time 后台

1.守护脚本

  一般用来检测项目中程序是否奔溃退出,以及程序重启多次后直接重启整个机器。

#!/bin/sh
yd_media_app &
count=0

while true
do
    stillRunning=$(ps | grep "yd_media_app" | grep -v "grep")
    if [ -z "$stillRunning" ]; then
        echo "yd_media_app not running, restart"
        if [ $count -eq 0 ]; then
            start_time=$(date +%s)
        elif [ $count -eq 3 ]; then
            end_time=$(date +%s)
            cost_time=$((end_time-start_time))
            echo "cost_time:"$cost_time
            if [ $cost_time -lt 60 ]; then
                reboot
            fi
        fi
        count=$((count+1))
        yd_media_app &
    fi
    sleep 1
done

 

标签:count,Shell,程序运行,media,app,yd,cost,time,后台
From: https://www.cnblogs.com/zhuangquan/p/16903287.html

相关文章