我对 Unix 系统文件表感到困惑。
当两个或多个进程打开一个文件进行读取时,系统文件表是为每个进程创建单独的条目还是单个条目?
如果为打开同一文件的多个进程创建单个条目,它们的文件偏移量也会相同吗?
If process 1
opens file1.txt
用于阅读和process 2
打开同一个文件file1.txt
对于写入,系统文件表会创建一个或两个条目吗?
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 www.cs.ucsb.edu now on archive.org https://web.archive.org/web/20160619025634if_/http://www.cs.ucsb.edu/%7Erich/class/cs170/notes/FileSystem/filetable.rich.jpg)
因此,打开的文件既没有一个文件表条目,也不是每个进程只有一个……每个进程都有一个open()
调用,如果文件描述符是共享的dup()
ed or fork()
ed.
回答您的问题:
-
当两个或多个进程打开一个文件进行读取时,每次打开的打开文件表中都会有一个条目。甚至每个打开都有一个条目,如果one进程多次打开文件。
-
单个条目是not在打开文件表中为打开同一文件的不同进程创建(但内存 inode 表中只有一项)。
-
如果 file1.txt 在相同或两个不同的进程中打开两次,则有两个不同的打开文件表条目(但在内存 inode 表中只有一个条目)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)