Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix system file tables

I am confused about Unix system file tables.

  • When two or more processes open a file for reading, does the system file table create separate entries for each process or a single entry?

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

  • 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?

like image 980
Alfred Avatar asked Jan 07 '13 04:01

Alfred


People also ask

What is Linux file table?

The Open File Table stores the information about all the files that are open while the OS is running.

What is system wide file table?

System Wide Open File Table contains a details of files which are opened by the processes. Ready List of Process Control Blocks (PCB), is a list of Process Control Blocks, which indicates the ready and terminated processes. Memory copy of File Allocation Table (FAT) contains details about files stored on the disk.

What is a vnode table?

Vnode Table. The kernel keeps yet another table, the Vnode table, which has an entry for each open file or device. Each entry, called a Vnode, contains information about the type of file and pointers to functions that operate on the file.

What are file descriptors in UNIX?

In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.


1 Answers

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: enter image description here (source: rich from www.cs.ucsb.edu now on archive.org)

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.

Answering your questions:

  1. 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.

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

  3. 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).

like image 94
Jim Balter Avatar answered Nov 07 '22 21:11

Jim Balter