#!/bin/bash

检查进程是否在运行的函数

function check_process { # 获取进程pid pid=$(ps -ef | grep "$1" | grep -v grep | awk '{print $2}') # 判断pid是否为空 if [ -z "$pid" ]; then # 进程未运行 echo 0 else # 进程已运行 echo 1 fi }

调用函数检查进程是否在运行

result=$(check_process "process_name") if [ $result -eq 1 ]; then echo "进程正在运行" else echo "进程未运行" fi

替换process_name为实际进程名称


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

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