feat: 添加kill_main.sh脚本以终止指定进程

This commit is contained in:
晓丰 2025-06-10 20:56:53 +08:00
parent 72794508fb
commit a97ed5efbf

25
kill_main.sh Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# -------- 可按需修改 --------
TARGET="/opt/ql/DailyMotion/main.py" # 关键字:精确到脚本路径即可
SIG="9" # 信号;默认 -9想温和一点改成 15
# --------------------------------
pids=$(ps -eo pid,cmd | grep "$TARGET" | grep -v grep | awk '{print $1}')
ppids=$(printf "%s\n" $pids | xargs -r ps -o ppid= -p | tr -s ' \n')
# 合并并去重
all=$(printf "%s\n%s\n" "$pids" "$ppids" | sort -u | tr '\n' ' ')
if [ -z "$all" ]; then
echo "没有发现正在运行的 $TARGET"
exit 0
fi
echo "即将发送 SIG${SIG:-15} 到进程: $all"
kill "-${SIG}" $all
echo "完成"