Reputation: 22
As you may know, the file descriptors in a process identifies a file operation (reading, writting...). When we make operations with these files we have to communicate with the OS since it's the one which manages files. With this purpose, the OS has a intermmediate pointer table in which for every single opened FD in every process, a entry is created. This table contains information (file pointer, type of operation...) about all the opened FDs. My question is, what happens in this table when a process is forked? My intuitive answer is that the entries of the table that belong to the forked process are duplicated at the table in order to have other intermediate pointers in the child process but I haven't found any info about this so I'd be glad to someone clarify this.
Thanks beforehand =)
Upvotes: 0
Views: 63
Reputation: 43317
The table is duplicated. The duplication isn't just a memcpy()
and outstanding IO only completes in the parent process. The child inherits all handles from the parent. The kernel file objects themselves are not duplicated but only their table references.
Upvotes: 1