地址已经在使用,但没有在netstat或lsof

我尝试在端口7054上启动Python SimpleHTTPServer:

$ sudo python -m SimpleHTTPServer 7054 ... socket.error: [Errno 98] Address already in use 

所以,我运行了以下命令:

 $ sudo netstat -ntpu | grep 7054 $ sudo lsof -i -n -P | grep 7054 

但是我没有结果。

netstat页:

 netstat [address_family_options] [--tcp|-t] [--udp|-u] [--raw|-w] [--listening|-l] [--all|-a] [--numeric|-n] [--numeric-hosts] [--numeric-ports] [--numeric-users] [--symbolic|-N] [--extend|-e[--extend|-e]] [--timers|-o] [--program|-p] [--verbose|-v] [--continuous|-c] 

我使用以下选项:

 sudo netstat -tanl | grep 7054 

它是--tcp ,– --tcp ,– --tcp ,– --tcp

我认为你需要显示侦听特定端口进程的pid的最小netstat选项是-nlp

您指定的lsof选项适用于我。 使用https://wiki.python.org/moin/UdpCommunication#Receiving中的示例代码和python -m SimpleHTTPserver 7054

 $ netstat -nlp | grep 7054 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 0.0.0.0:7054 0.0.0.0:* LISTEN 20458/python udp 0 0 0.0.0.0:7054 0.0.0.0:* 20498/python $ lsof -i -n -P | grep 7054 python 20458 michael 3u IPv4 143736 0t0 TCP *:7054 (LISTEN) python 20498 michael 3u IPv4 173739 0t0 UDP *:7054 

额外的信用:坚持一个别名:

 listening() { netstat -nlp | grep $1 } 

并使用它:

 $ listening 7054