首页 > 代码库 > Windows和Linux下如何查看端口被哪个进程占用
Windows和Linux下如何查看端口被哪个进程占用
Windows:
C:/Users/ewanbao>netstat -aon|findstr "123"
TCP 127.0.0.1:55123 0.0.0.0:0 LISTENING 5092
TCP 127.0.0.1:55123 127.0.0.1:55124 ESTABLISHED 5092
TCP 127.0.0.1:55124 127.0.0.1:55123 ESTABLISHED 5092
UDP 0.0.0.0:123 *:* 1416
UDP [::]:123 *:* 1416
[注]:执行netstat -aon|findstr "123"以后,就可以看到5092进程中TCP打开123端口,1416进程打开UDP123端口
C:/Users/ewanbao>tasklist|findstr "1416"
svchost.exe 1416 Services 0 13,540 K
[注]:执行tasklist|findstr "1416"后就可以看到是svchost.exe在UDP打开123端口
Linux:
cba001:~ # lsof -i:5300
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
named 26751 root 20u IPv4 64750499 TCP localhost:hacl-hb (LISTEN)
named 26751 root 21u IPv4 64750501 TCP cba001.eapac:hacl-hb (LISTEN)
named 26751 root 22u IPv4 64750503 TCP 192.168.0.10:hacl-hb (LISTEN)
named 26751 root 512u IPv4 64750498 UDP localhost:hacl-hb
named 26751 root 513u IPv4 64750500 UDP cba001.eapac:hacl-hb
named 26751 root 514u IPv4 64750502 UDP 192.168.0.10:hacl-hb
[注]:执行lsof -i:5300以后就可以看到26751进程在TCP和UDP上都打开了5300端口.
cba001:~ # ps -ef|grep 26751
root 10118 26915 0 12:59 pts/8 00:00:00 grep 26751
root 26751 1 0 Jul06 ? 00:02:06 /opt/ipworks/IPWdns/usr/bin/named
[注]:执行ps -ef|grep 26751以后就可以看到是named进程打开了5300端口
Windows和Linux下如何查看端口被哪个进程占用