创建管道、fifo 或套接字时创建 inode
我有关于 Linux 的一般问题。如果我创建了fifo,inode也会创建吗?管道?插座?
I have general question about Linux. Will the inode be created if I create a fifo? pipe? socket?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Linux 上,可以从
/proc//fd
目录获得答案。引用/proc
文档 ( man 5 proc< /a> ):让我们验证一下:
那么管道和套接字会有索引节点吗?是的 ! FIFO 怎么样?我们可以猜测,由于它们有文件名,所以它们确实有索引节点(并且我认为没有索引节点的目录条目不能存在 )。但让我们验证一下:
答案是“是的,FIFO 也有 inode”。
然而,这提出了一个重要的问题:索引节点是文件系统的属性,并且索引节点在文件系统中并不是唯一的,因此当我们看到管道 inode 时正在引用哪个文件系统?好吧,事实证明存在
pipefs
虚拟文件系统安装在内核空间,而不是用户空间。它管理管道和 FIFO,因此您在/proc
示例中看到的 inode 编号是这些文件系统的属性,而不是磁盘上的文件系统的属性。是的,匿名管道和匿名套接字在磁盘文件系统上不会有 inode,因为磁盘上没有文件名和字节(尽管可能有数据缓存,实际上旧的 Unix 将管道缓存到磁盘)。然而,FIFO 和 Unix 域套接字在文件系统上有文件名,因此在 foobar.fifo 示例中,inode 属于磁盘文件系统。另请参阅:
On Linux the answer can be obtained from
/proc/<PID>/fd
directory. To quote/proc
documentation ( man 5 proc ):Let's verify that:
So will pipes and sockets have an inode ? Yes ! What about FIFOs ? We can guess that since they have a filename, they do have inode ( and I don't think directory entries without inode can exist ). But lets verify:
The answer is "yes, FIFOs have inodes,too".
However, this raises an important question: inodes are properties of filesystems, and inodes aren't unique accross filesystems, so which filesystem is being referenced when we see a pipe inode ? Well, turns out there exists
pipefs
virtual filesystem which is mounted in Kernel space, rather than userspace. It manages both pipes and FIFOs, so the inode number you see is the/proc
example is the property of those filesystems, rather than the filesystem you have on disk. And yes, anonymous pipes and anonymous sockets won't have inode on disk filesystem, because there's no filename and no bytes on disk (although there may be caching of data, and in fact old Unixes cached pipes to disk). FIFOs and Unix-domain sockets, however, have filename on the filesystem, so infoobar.fifo
example that inode belongs on the disk filesystem.See also:
不会为匿名管道或套接字创建索引节点,因为索引节点是文件系统的属性,而这两者都不是文件系统实体(它们没有文件路径)。它们只有文件描述符。
然而,对于命名管道(又名fifo),索引节点是在作为文件系统实体存在时创建的。
No inode will be created for an anonymous pipe or a socket, as an inode is a property of a filesystem and neither of these two lives as a filesystem entity (they don't have a file path). They only have file descriptors.
However, for named pipes (aka fifo) an inode is created as it lives as an filesystem entity.