#!/bin/bash

指定待监控的进程名称

PROCESS_NAME='my_process'

检查进程是否存在

PROCESS_ID=$(ps -ef | grep '${PROCESS_NAME}' | grep -v grep | awk '{print $2}') if [ -z '${PROCESS_ID}' ]; then # 进程不存在,启动程序 echo 'Process ${PROCESS_NAME} is not running, starting it now...' nohup /path/to/my_program > /dev/null 2>&1 & else # 进程已经存在 echo 'Process ${PROCESS_NAME} is running with PID ${PROCESS_ID}.' fi

退出脚本

exit 0


原文地址: https://www.cveoy.top/t/topic/nPfc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录