Reputation: 8152
Do file descriptor are with respect to the processes or with respect to the operating system? What I basically want to know is if in a c program I open a file and that file gets assigned a file descriptor value lets say, 103, so when I open a file with file descriptor 103 in some other c program would I be referring to the same file or some other?
Upvotes: 1
Views: 375
Reputation: 1822
File descriptors are process specific created through open(). But you can open same file more than once by other processes with open(). In this way each process will have his own file descriptor for same file. File descriptors along with other resources pass through fork to child process.That means child process does not need to reopen same file which parent already has opened.
Upvotes: 0
Reputation: 1746
Each Process will be having its own file descriptor table. Its processor specific, if you change the fd
it will be valid only to that process it wont affect the other processes in the system. once process is terminated fd
will be discarded.
What if I fork a new process from the process I opened that file?
Current File description table i.e the table before fork system call will be inherited to the child process.
Upvotes: 1