How does kernel know file is closed
What exactly is the mechanism by which the linux knows that a file has been closed ? I know commands such as INOTIFY would trigger IN_CLOSE_WRITE event when a file is closed. But how does it work ? What trig开发者_开发技巧gers close of a file ?
Similarly how does OS know that a file has been opened and where does it register that fact?
The OS (i.e. kernel) is the one that actually opens and closes files. A program will have to tell the OS to open/close files on its behalf every time it wants to do so via system calls. The OS can simply keep track of these calls that go through itself.
There is an open file table that lists all the streams that are open and where they point to in memory.
This may help: http://www.cs.kent.edu/~walker/classes/os.f07/lectures/Walker-11.pdf
精彩评论