linux - linux内核如何知道哪个inotify_handle有某个watch

标签 linux filesystems kernel inotify

我了解到linux内核提供了“inotify机制”来监控文件系统。

根据 inotify,inotify_init() 返回 fd 以从内核接收 inotify_event。 (我知道内核会在上面写 inotify_event。)

1) 如果我使用 inotify_add_watch() 添加带有 inotify fd 的新 watch ,当watched 文件有一个事件。

2) (如果内核有,)当内核检测到监视文件的事件时,内核如何决定哪个 inotify fd(inotify_instance) 必须使用此 inotify_event 更新?

最佳答案

我自己的研究,这是答案:

  1. 是linux内核;特别是文件系统。
  2. 当你调用 inotify_add_watch() 到某个文件时,inotifyinotify watch 的一些信息存储到该文件的 inode结构。

然后,每当文件系统处理该文件时,它都会检查文件的 inode 结构 - 是否存在 inotify watches。如果 inotify watches 从 inode 结构中找到,inotify 报告 inotify_event

关于linux - linux内核如何知道哪个inotify_handle有某个watch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7885529/

相关文章:

linux - find 命令的 "exec"功能可以在后台启动程序吗?

linux - Linux/Hadoop集群的配置管理

c - libpcap : 64bit machine has no compatible 32-bit libpcap library

java - Android 中的并发文件访问

java - 创建 Java NIO 文件系统时, "env"选项(及其用途)是什么?

linux - Linux内核中的原子操作

linux - 使用 e1000e 网络驱动程序而不是 tg3

google-chrome - 调用showOpenFilePicker : how avoid "must come from gesture" when calling class methods

linux - 函数声明而不是注释

c - 用于实模式内核开发的 16 位 C 编译器?