Commit bbea6731 by imwangxiaozhou

fix(stop.sh): 改进进程停止逻辑并增强错误处理

- 添加权限检查,当普通 kill 失败时提示用户使用 sudo
- 将强制 kill 也重定向错误输出以避免干扰
- 改进进程不存在时的提示信息,明确说明正在清理 PID 文件
1 parent d697e3b0
Showing 1 changed file with 9 additions and 3 deletions
...@@ -20,14 +20,20 @@ stop_process() { ...@@ -20,14 +20,20 @@ stop_process() {
PID=$(cat "$pid_file") PID=$(cat "$pid_file")
if ps -p $PID > /dev/null 2>&1; then if ps -p $PID > /dev/null 2>&1; then
echo "正在停止 $name (PID: $PID)..." echo "正在停止 $name (PID: $PID)..."
kill $PID # 尝试普通 kill,如果失败则提示用户
if ! kill $PID 2>/dev/null; then
echo "错误: 无法停止 $name (PID: $PID)。"
echo "原因: 权限不足。请尝试使用 sudo 运行: sudo ./stop.sh"
return 1
fi
sleep 1 sleep 1
if ps -p $PID > /dev/null 2>&1; then if ps -p $PID > /dev/null 2>&1; then
kill -9 $PID kill -9 $PID 2>/dev/null
fi fi
echo "$name 已停止。" echo "$name 已停止。"
else else
echo "警告: $name 进程已不存在。" echo "警告: $name 进程已不存在,正在清理 PID 文件。"
fi fi
rm "$pid_file" rm "$pid_file"
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!