简体   繁体   English

如何找到TCP套接字的inode?

[英]How do I find the inode of a TCP socket?

How do I tie values in the 'inode' column of /proc/net/tcp to files in /proc/<pid>/fd/ ? 如何将/proc/net/tcp的'inode'列中的值绑定到/proc/<pid>/fd/

I was under the impression that the inode column in the TCP had a decimal representation of the socket's inode, but that doesn't seem to be the case. 我的印象是TCP中的inode列有一个套接字inode的十进制表示,但似乎并非如此。

For example, if I run telnet localhost 80 , I see the following (telnet is pid 9021). 例如,如果我运行telnet localhost 80 ,我会看到以下内容(telnet是pid 9021)。

/proc/net/tcp contains /proc/net/tcp包含

sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
23: 0100007F:CE2A 0100007F:0050 01 00000000:00000000 00:00000000 00000000  1000        0 361556 1 00000000 20 0 0 10 -1

which makes me think that the inode of the socket connected to 127.0.0.1:80 is 361556. But if I run ls --inode -alh /proc/9021/fd , I see 这让我觉得连接到127.0.0.1:80的套接字的inode是361556.但如果我运行ls --inode -alh /proc/9021/fd ,我看到

349886 lrwx------ 1 me me 64 Dec 26 10:51 3 -> socket:[361556]

The inode is 349886, which is different from the value in the inode column of the tcp table: 361556. But the link target seems to have the right name. inode是349886,它与tcp表的inode列中的值不同:361556。但链接目标似乎具有正确的名称。 Similarly, stat /proc/9021/3 shows: 同样, stat /proc/9021/3显示:

File: ‘/proc/9021/fd/3’ -> ‘socket:[361556]’
Size: 64            Blocks: 0          IO Block: 1024   symbolic link
Device: 3h/3d   Inode: 349886      Links: 1

What's the number in the inode column of tcp table? tcp表的inode列中的数字是多少? Why doesn't it line up with the inode as reported by ls or stat ? 为什么它不与lsstat报告的inode stat

(I'm running Ubuntu 14.10, if that matters) (我正在运行Ubuntu 14.10,如果这很重要)

The inode shown by ls and stat is for the symlink that points to the inode associated with the socket. lsstat显示的inode用于指向与套接字关联的inode的符号链接。 Running ls -iLalh shows the right inode. 运行ls -iLalh显示正确的inode。 Ditto for stat -L . 同样的stat -L

Herpa derp derp. Herpa derp derp。 I only figured this out when I was composing my question. 当我撰写我的问题时,我才想到这一点。 ;_; ; _;

Inode id represent a file id per fs mount (proc, sys, ntfs, ext...), so as you probably understand you deal with two different fs here: procfs and some pseudo socket fs. Inode id代表每个fs mount(proc,sys,ntfs,ext ...)的文件id,所以你可能理解你在这里处理两个不同的fs:procfs和一些伪套接字fs。

The files under the /proc/pid/fd/ directories are soft links which have inode representation in the procfs fs. / proc / pid / fd /目录下的文件是软链接,在procfs fs中有inode表示。 These links are "pointing" to different "fs" - socket fs. 这些链接“指向”不同的“fs” - 套接字fs。

What stat -L and ls -iLalh do, is to give you the inode of the file the links points to. stat -Lls -iLalh做的是给你链接指向的文件的inode。 You can do this also explicitly with readlink /proc/#pid/fd/#fdnum 您也可以使用readlink /proc/#pid/fd/#fdnum明确地执行此readlink /proc/#pid/fd/#fdnum

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM