内核如何知道文件已关闭
Linux 知道文件已关闭的机制到底是什么? 我知道诸如 INOTIFY 之类的命令会在文件关闭时触发 IN_CLOSE_WRITE 事件。但它是如何运作的呢?什么触发文件关闭?
同样,操作系统如何知道文件已被打开以及它在哪里注册该事实?
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 triggers close of a file ?
Similarly how does OS know that a file has been opened and where does it register that fact?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
操作系统(即内核)是实际打开和关闭文件的操作系统。程序每次想要通过系统调用来打开/关闭文件时,都必须告诉操作系统代表它打开/关闭文件。操作系统可以简单地跟踪这些经过自身的调用。
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.
有一个打开文件表,列出了所有打开的流以及它们在内存中的指向位置。
这可能会有所帮助:http://www. cs.kent.edu/~walker/classes/os.f07/lectures/Walker-11.pdf
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