LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What does closing an file descriptor mean? (https://www.linuxquestions.org/questions/programming-9/what-does-closing-an-file-descriptor-mean-868249/)

rainman1985_2010 03-13-2011 03:13 AM

What does closing an file descriptor mean?
 
As we know, every process has a table with a file descriptor table, in which each entry contains a file pointer pointing to the corresponding file table which contains a v-node pointer pointing to the v-node table.

When closing a file descriptor, are all these data structure deleted?

bastl 03-13-2011 10:31 AM

Once the kernel has opened a file by name it stores that "file connection" under that descriptor number for faster access.
The structure is like that of system descritors, so the name.
An app. has no access to its file descriptor table only the kernel has.
Closing a file descriptor means the kernel writes all buffered data to the coresponding file.
A nother process can then read the actual data out of this file by sure (all is saved).
A file descriptor keeps alive until the app exits, even if the file is closed.
Closing a file means closing or deleting a file descriptor, what is not really done.

jtshaw 03-13-2011 12:56 PM

Also keep in mind file descriptors are a finite resource. Long running programs that burn thought them and never close them can cause system problems because nothing will be able to open up files (or sockets).


All times are GMT -5. The time now is 04:02 PM.