The shell script monitors whether the process exists and restarts

#! /bin/bash
if test $( pgrep -f 进程名 | wc -l ) -eq 0
then
echo "jmap进程不存在"
else
echo "jmap进程存在"
ps -ef | grep 进程名 | grep -v grep | awk '{
    
    print $2}' | xargs kill -9
echo "jmap进程杀掉成功"
fi

Guess you like

Origin blog.csdn.net/qq_37741426/article/details/128532552