加入收藏 | 设为首页 | 会员中心 | 我要投稿 云计算网_宿迁站长网 (https://www.0527zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Unix > 正文

Unix 系统文件表

发布时间:2022-10-20 14:01:58 所属栏目:Unix 来源:网络
导读: 本文介绍了Unix 系统文件表的处理方法unix系统文件,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 Unix 系统文件表感到困惑.
I am confused

本文介绍了Unix 系统文件表的处理方法unix系统文件,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Unix 系统文件表感到困惑.

I am confused about Unix system file tables.

如果为打开同一个文件的多个进程创建一个条目,它们的文件偏移量是否也相同?

If a single entry is created for multiple processes opening the same file, will their file offsets also be the same?

如果 process 1 打开 file1.txt 进行读取并且 process 2 打开相同的文件 file1.txt写入,系统文件表会创建一两个条目吗?

If process 1 opens file1.txt for reading and process 2 opens the same file file1.txt for writing, will the system file table create one or two entries?

推荐答案

有三个系统文件表":有一个文件描述符表,将文件描述符(小整数)映射到打开的文件表中的条目.打开文件表中的每个条目都包含(除其他外)一个文件偏移量和一个指向内存 inode 表的指针.这是一张图片:(来源:rich 来自 现在在 archive.org)

There are three "system file tables": There is a file descriptor table that maps file descriptors (small integers) to entries in the open file table. Each entry in the open file table contains (among other things) a file offset and a pointer to the in-memory inode table. Here's a picture: (source: rich from now on archive.org)

因此,对于打开的文件,既没有一个文件表条目,也没有每个进程只有一个……每个 open() 调用都有一个,如果文件描述符是 dup()ed 或 fork()ed.

So there is neither just one file table entry for an open file nor is there just one per process ... there is one per open() call, and it is shared if the file descriptor is dup()ed or fork()ed.

回答您的问题:

当两个或多个进程打开一个文件进行读取时,每次打开的文件表中都会有一个条目.如果一个进程多次打开文件,甚至每次打开都会有一个条目.

When two or more processes open a file for reading, there's an entry in the open file table per open. There is even an entry per open if one process opens the file multiple times.

在打开文件表中不会为打开同一文件的不同进程创建单个条目(但在内存 inode 表中只有一个条目).

A single entry is not created in the open file table for different processes opening same file (but there is just one entry in the in-memory inode table).

如果 file1.txt 在同一个或两个不同的进程中被打开两次,则有两个不同的打开文件表条目(但在内存 inode 表中只有一个条目).

If file1.txt is opened twice, in the same or two different processes, there are two different open file table entries (but just one entry in the in-memory inode table).

这篇关于Unix 系统文件表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

(编辑:云计算网_宿迁站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!