Shell 脚本监控进程并自动启动 - 定时执行
#!/bin/bash
定义要监控的进程名称
process_name='myprogram'
判断进程是否存在
if pgrep '$process_name' >/dev/null 2>&1; then echo '$process_name is running.' else echo '$process_name is not running. Starting...' # 启动对应的程序 /path/to/myprogram & fi
定时执行该脚本(例如每5分钟执行一次)
sleep 300 exec '$0'
原文地址: https://www.cveoy.top/t/topic/nPf9 著作权归作者所有。请勿转载和采集!