一. 遇到的问题
- 使用python开启一个服务,占用服务器的
8089端口
bash
python3 -m http.server 8089 --bind 127.0.0.1
- 假设只知道
8089端口被占用,但是想知道具体是被哪个程序占用的话,该怎么查询呢❓

二. 解决办法
ss -lntp | grep ':8089'→ 查看8089端口相关的信息-l:listening,只看监听中的端口-n:numeric,以数字形式显示 IP 和端口,不做 DNS 解析-t:tcp,只看 TCP-p:process,显示对应进程
lsof -i :8089→ 查看8089端口相关的信息-i:Internet address,和网络相关。
ps -fp 22→ 查看进程ID为22的相关信息ps:查看进程状态。-f:Full format,完整格式显示。-p:Process ID,进程ID。
bash
apluser@FengYeHong-HP:~$
apluser@FengYeHong-HP:~$ ss -lntp | grep ':8089'
LISTEN 0 5 127.0.0.1:8089 0.0.0.0:* users:(("python3",pid=22,fd=3))
apluser@FengYeHong-HP:~$
apluser@FengYeHong-HP:~$ lsof -i :8089
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python3 22 apluser 3u IPv4 1247 0t0 TCP localhost:8089 (LISTEN)
apluser@FengYeHong-HP:~$
apluser@FengYeHong-HP:~$ ps -fp 22
UID PID PPID C STIME TTY TIME CMD
apluser 22 13 0 20:40 pts/0 00:00:00 python3 -m http.server 8089 --bind 127.0.0.1
apluser@FengYeHong-HP:~$