如何找到TCP套接字的索引节点? [英] How do I find the inode of a TCP socket?

查看:226
本文介绍了如何找到TCP套接字的索引节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将/proc/net/tcp的'inode'列中的值绑定到/proc/<pid>/fd/中的文件?

How do I tie values in the 'inode' column of /proc/net/tcp to files in /proc/<pid>/fd/?

给我的印象是,TCP中的inode列具有套接字的inode的十进制表示,但事实并非如此.

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.

例如,如果我运行telnet localhost 80,则会看到以下内容(telnet是pid 9021).

For example, if I run telnet localhost 80, I see the following (telnet is pid 9021).

/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

这使我认为连接到127.0.0.1:80的套接字的inode是361556.但是如果我运行ls --inode -alh /proc/9021/fd,我会看到

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

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

inode是349886,它与tcp表的inode列中的值不同:361556.但是链接目标似乎具有正确的名称.同样,stat /proc/9021/3显示:

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. Similarly, stat /proc/9021/3 shows:

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

tcp表的inode列中的数字是多少?为什么它不与lsstat报告的inode对齐?

What's the number in the inode column of tcp table? Why doesn't it line up with the inode as reported by ls or stat?

(如果重要的话,我正在运行Ubuntu 14.10)

(I'm running Ubuntu 14.10, if that matters)

推荐答案

lsstat所示的inode用于指向与套接字关联的inode的符号链接.运行ls -iLalh显示正确的inode. stat -L的同上.

The inode shown by ls and stat is for the symlink that points to the inode associated with the socket. Running ls -iLalh shows the right inode. Ditto for stat -L.

Herpa derp derp.我只是在撰写问题时才弄清楚这一点. ; _;

Herpa derp derp. I only figured this out when I was composing my question. ;_;

这篇关于如何找到TCP套接字的索引节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆