sh

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
port=8080 # 将8080替换成你想要查找和杀死的端口号

# 查找端口的进程ID
pid=$(lsof -ti :$port)

# 杀死进程
if [[ -n "$pid" ]]; then
echo "Killing process $pid listening on port $port"
kill -9 $pid
else
echo "No process listening on port $port"
fi