kill_port.sh
#!/bin/bash
# 检查是否提供了端口号
if [ -z "$1" ]; then
echo "Usage: $0 <port>"
exit 1
fi
PORT=$1
# 查找占用指定端口的进程
PIDS=$(sudo lsof -t -i :$PORT)
if [ -z "$PIDS" ]; then
echo "No processes found using port $PORT"
exit 0
fi
# 终止每个进程
for PID in $PIDS; do
echo "Killing process with PID $PID"
sudo kill -9 $PID
done
echo "All processes using port $PORT have been terminated."
欢迎来撩 : 汇总all