How can i match each /proc/net/tcp entry to each o

2020-01-29 06:00发布

I'm trying to parse socket info from /proc/net/tcp and while I can identify some fields, such as memory addresses or send queue use, I can't find how each entry is bound to its socket descriptor. e.g., with this data:

1: 5922140A:E459 D5C43B45:0050 01 00000000:00000000 00:00000000 00000000  1000        0 507218 1 f6ab1300 57 3 12 4 -1  

I want to know which is the correspondant socket descriptor.

2条回答
你好瞎i
2楼-- · 2020-01-29 06:30

Take the inode number (in this case, 507218). Each open file descriptor to that socket (there may be multiple file descriptors for the same socket) will appear as a link of the form:

/proc/<PID>/fd/<N> -> socket[507218]

(where <PID> is the process ID and <N> is the file descriptor).

查看更多
ゆ 、 Hurt°
3楼-- · 2020-01-29 06:38

Depends on the architecture as to how /proc can be formatted, but on Linux:

http://linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html

查看更多
登录 后发表回答