开发者

How does kernel know file is closed

开发者 https://www.devze.com 2023-04-05 03:05 出处:网络
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 ? Wh

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号