gpt4 book ai didi

python - 地址已被使用但在 netstat 或 lsof 中没有任何内容

转载 作者:IT王子 更新时间:2023-10-29 00:27:46 24 4
gpt4 key购买 nike

我尝试在端口 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

也就是--numeric, --tcp, --all, --listening

我认为显示监听特定端口的进程 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

关于python - 地址已被使用但在 netstat 或 lsof 中没有任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23907095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com