Why to use inotify

inotify is very useful in many situations where reactions on file system changes are necessary. Without inotify it can be implemented by periodical (or manually requested) examining files and directories. But such way is slow and wastes processor time. inotify brings very fast and economical method how to react on file system changes.

inotify works as a regular "file" device. Thus you can use normal system calls and functions like read(), select(), poll(), ioctl(FIONREAD) or close(). For maximum performance, many different files can be monitored through one inotify instance (one file descriptor).

Unlike its ancestor dnotify, inotify doesn't complicate your work by various limitations. For example, if you watch files on a removable media these file aren't locked. In comparison with it, dnotify requires the files themselves to be open and thus really "locks" them (hampers unmounting the media).

inotify queues all events into (per-instance) queues. Thus these events can be read later en bloc. The maximum lenght of these queues (and also the maximum number of watches per instance and the maximum number of instances per process) are changeable through procfs files.

English  Czech    [RSS]