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)
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:
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.
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).
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).
fork
. Processes are created by thefork
system call. Thus, they are essentially the same question. – Corse