Files
Work-configuration-file/sh/kill_lessie_sourcing_agents.sh

24 lines
630 B
Bash
Raw Normal View History

2025-11-26 14:11:03 +08:00
#!/bin/bash
# 从参数获取端口号
PORT=$1
# 判断是否传入参数
if [ -z "$PORT" ]; then
echo "❌ 错误:请在执行时指定端口号,例如: sh kill_lessie_sourcing_agents.sh 8000"
exit 1
fi
# 查找占用端口的进程 PID
# PID=$(lsof -t -i:$PORT)
PID=$(lsof -iTCP -sTCP:LISTEN -nP | awk -v port=":$PORT" '$9 ~ port"$" {print $2}' | sort -u)
if [ -n "$PID" ]; then
echo "发现端口 $PORT 的进程PID=$PID"
echo "正在关闭进程..."
kill -9 $PID
echo "进程 $PID 已经被杀掉,端口 $PORT 已释放。"
else
echo "端口 $PORT 没有正在运行的进程。"
fi