linux /proc/[pid]/fd 中socket描述符后面的数字是什么意思?inode(information node)

背景

在这里插入图片描述
ls -l /proc/[pid]/fd 命令查看进程文件描述符,发现socket描述符后面都带着一个数字

这是什么意思?

解答

可以查看的man手册proc(5) :man 5 proc

$ man proc
...
/proc/[pid]/fd/
    This is a subdirectory containing one entry for each file  which  the  process  has  open,
    named by its file descriptor, and which is a symbolic link to the actual file.  Thus, 0 is
    standard input, 1 standard output, 2 standard error, and so on.

    For file descriptors for pipes and sockets, the entries will be symbolic links whose  con‐
    tent is the file type with the inode.  A readlink(2) call on this file returns a string in
    the format:

        type:[inode]

    For example, socket:[2248868] will be a socket and its inode  is  2248868.   For  sockets,
    that inode can be used to find more information in one of the files under /proc/net/.
...

可以看到,socket:[2248868]后面数字2248868代表inode。

inode是什么?

文件系统中,inode这里的 i 可用理解成information node, inode Table专门用于存放文件的描述信息(区别于文件数据), 如文件类型(常规, 目录, fifo文件, 符号链接等), 访问权限, 文件大小, 创建、最后一次修改/访问时间(可用ls -l命令查询).每个文件都有一个inode, 一个块组(Block Group)中所有inode组成inode表.inode表总共占多少个块在格式化的时候, 就要决定并写入块组描述符, 由GDT/配置信息管理. mke2fs(格式化工具)的默认策略是一个块组有多少个8KB, 就分配多少个inode.

inode与socket关系?

在文件系统中,每个磁盘有多个分区,每个分区有多个柱面组,每个柱面组有一个inode数组。上面的数字2248868代表inode的一个编号,称为inode编号。可以用来唯一标识改该文件,也可以定位inode在磁盘中的位置。在socketfs虚拟文件系统中,socket对应的inode并不像普通的文件系统,位于磁盘上,而是位于内核的socket结构中(内存)。类似地,socket的inode也可以唯一标识当前socket通信连接。

参考:
linux:从linux内核出发彻底弄懂socket底层的来龙去脉

Linux套接字与虚拟文件系统(1):初始化和创建

【网络】Socket底层讲解

APUE Unix/Linux文件系统


转载自:linux socket描述符后面的数字是什么意思? - 张明明的回答 - 知乎

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值