1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #!/bin/bash
# 设置jar包名称通配符 jar_pattern="wwh-test.*.jar"
# 查找正在运行的jar包的进程ID pids=$(ps -ef | grep "$jar_pattern" | grep -v grep | awk '{print $2}')
# 如果找到正在运行的进程,就停止它 if [ -n "$pids" ]; then echo "正在停止匹配 $jar_pattern 的进程..." for pid in $pids; do echo "停止进程 $pid" kill -15 "$pid" done
# 循环检查进程是否已经停止 for pid in $pids; do while kill -0 "$pid" >/dev/null 2>&1; do echo -n "." sleep 1 done echo "进程 $pid 已停止." done
echo "所有进程已停止." else echo "未找到匹配 $jar_pattern 的进程." fi
|