首页 > 解决方案 > 哪个线程监听特定的 UDP 端口

问题描述

我跑了:

# lsof | grep 10900

及其输出:

MyExecutab 103497        myuser    7u     IPv4             985833       0t0        UDP my.example.com:10900 
MyExecutab 103497 103498 myuser    7u     IPv4             985833       0t0        UDP my.example.com:10900 
MyExecutab 103497 103499 myuser    7u     IPv4             985833       0t0        UDP my.example.com:10900 
MyExecutab 103497 103500 myuser    7u     IPv4             985833       0t0        UDP my.example.com:10900 
MyExecutab 103497 103501 myuser    7u     IPv4             985833       0t0        UDP my.example.com:10900 
MyExecutab 103497 103502 myuser    7u     IPv4             985833       0t0        UDP my.example.com:10900 
MyExecutab 103497 103503 myuser    7u     IPv4             985833       0t0        UDP my.example.com:10900 

我试图找出哪个线程正在从 UDP 端口 10900 读取。

似乎有 7 个线程从该端口读取,是真的吗?

我觉得实际上只有一个线程正在读取,但 lsof 只是列出了所有子线程(在同一进程中)和父线程。

netstat -plun显示只有父线程 (PID) 正在侦听该端口:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
udp        0      0 10.7.168.173:10900      0.0.0.0:*                           103497/MyExecutable 

我也查了/proc/[pid]/fd。因为只有103497是PID,其余都是TID,所以/proc/只有103497,其余没有。

那么真的有办法找出哪个线程监听特定的 UDP 端口吗?

我在 CentOS 7(内核 3.10)上。

谢谢!

标签: linuxmultithreadingudpnetstatlsof

解决方案


运行strace -ffp <pid>并查看哪些线程使用文件描述符 7。


推荐阅读