linux
中,很容易的可以用netstat -tnlp
查看出端口的占用情况,但该命令在mac上被大大简化,比如-p
命令不支持:
$ netstat -tnlp | grep 8000
netstat: option requires an argument -- p
Usage: netstat [-AaLlnW] [-f address_family | -p protocol]
netstat [-gilns] [-f address_family]
netstat -i | -I interface [-w wait] [-abdgRtS]
netstat -s [-s] [-f address_family | -p protocol] [-w wait]
netstat -i | -I interface -s [-f address_family | -p protocol]
netstat -m [-m]
netstat -r [-Aaln] [-f address_family]
netstat -rs [-s]
但如果只用netstat -tnl | grep 8000
则查不出任何东西,显然是不对的
此时可以用:
netstat -anv | grep 8000
$ netstat -anv | grep 8000
tcp4 0 0 127.0.0.1.8000 *.* LISTEN 131072 131072 62410 0 0x0000 0x00000006
tcp46 0 0 *.8000 *.* LISTEN 131072 131072 38336 0 0x0100 0x00000026
可以看到,pid
以及被哪个进程占用还是不知道,这时只能用lsof
命令了:
$ lsof -i:8000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
main 38336 mac 6u IPv6 0x8736b0dd601c8911 0t0 TCP *:irdmi (LISTEN)
Python 62410 mac 23u IPv4 0x8736b0dd4e023851 0t0 TCP localhost:irdmi (LISTEN)
网友评论