yolo_standard_libray/test_stop.sh
2025-03-07 11:35:40 +08:00

26 lines
846 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 定义一个函数来杀死匹配的Python进程
kill_python_processes() {
# 使用pgrep查找包含特定名称的Python进程
# 注意这里假设Python进程在命令行中包含了脚本名称
# -f 选项告诉pgrep考虑完整的命令行
pids=$(pgrep -f "python 02")
# 检查是否找到了进程
if [ -n "$pids" ]; then
# 对每个PID执行kill命令
for pid in $pids; do
echo "Killing Python process with PID: $pid"
kill $pid
# 可选如果进程不响应普通kill可以尝试使用kill -9强制杀死
# 如果上面的kill命令没有成功可以取消下面一行的注释
# kill -9 $pid
done
else
echo "No matching Python processes found."
fi
}
# 调用函数
kill_python_processes