HOME

TheInfoList



OR:

inotify (
inode The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attribute ...
notify) is a
Linux kernel The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
subsystem created by John McCutchan, which monitors changes to the
filesystem In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
, and reports those changes to applications. It can be used to automatically update directory views, reload configuration files, log changes, backup, synchronize, and upload. The ''inotifywait'' and ''inotifywatch'' commands (maintained by Eric Curtin as part of the inotify-tools project) allow using the inotify subsystem from the command line.inotify-tools wiki
/ref> One major use is in
desktop search Desktop search tools search within a user's own computer files as opposed to searching the Internet. These tools are designed to find information on the user's PC, including web browser history, e-mail archives, text documents, sound files, images ...
utilities like
Beagle The beagle is a breed of small scent hound, similar in appearance to the much larger foxhound. The beagle was developed primarily for hunting hare, known as beagling. Possessing a great sense of smell and superior tracking instincts, the ...
, where its functionality permits reindexing of changed files without scanning the filesystem for changes every few minutes, which would be very inefficient. inotify replaced an earlier facility,
dnotify dnotify is a file system event monitor for the Linux kernel, one of the subfeatures of the fcntl call. It was introduced in the 2.4 kernel series. It has been obsoleted by inotify, but will be retained for compatibility reasons. Its function is es ...
, which had similar goals. It was merged into the
Linux kernel mainline The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU oper ...
in kernel version 2.6.13, released on August 29, 2005;Linux 2.6.13, kernelnewbies.org
/ref> later kernel versions included further improvements. The required library interfaces were added into the
GNU C Library The GNU C Library, commonly known as glibc, is the GNU Project's implementation of the C standard library. Despite its name, it now also directly supports C++ (and, indirectly, other programming languages). It was started in the 1980s by ...
(glibc) in its version 2.4, released in March 2006, while the support for inotify was completed in glibc version 2.5, released in September 2006.inotify man page
/ref>


Limitations

Limitations imposed by inotify include the following: * Inotify does not support recursively watching directories, meaning that a separate inotify watch must be created for every subdirectory. In contrast, the command ''inotifywait'' does provide recursive watching of directories. * Inotify does report some but not all events in
sysfs sysfs is a pseudo file system provided by the Linux kernel that exports information about various kernel subsystems, hardware devices, and associated device drivers from the kernel's device model to user space through virtual files. In addition ...
and
procfs The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized metho ...
. * Notification via inotify requires the kernel to be aware of all relevant filesystem events, which is not always possible for networked filesystems such as NFS where changes made by one client are not immediately broadcast to other clients. * Rename events are not handled directly; i.e., inotify issues two separate events that must be examined and matched in a context of potential race conditions.


History

* July 2004: the first release announcement * August 29, 2005: Linux kernel version 2.6.13 released, containing merged inotify code * March 2006: GNU C Library (glibc) version 2.4 released, bringing initial inotify support * September 2006: Glibc version 2.5 released, bringing complete inotify support


Advantages over dnotify

There are a number of advantages when using inotify when compared to the older
dnotify dnotify is a file system event monitor for the Linux kernel, one of the subfeatures of the fcntl call. It was introduced in the 2.4 kernel series. It has been obsoleted by inotify, but will be retained for compatibility reasons. Its function is es ...
API that it replaced.inotify README file
/ref> With dnotify, a program had to use one
file descriptor In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket. File descriptors typically have ...
for each directory that it was monitoring. This can become a bottleneck since the limit of file descriptors per process could be reached. Later, fanotify was created to overcome this issue. The use of file descriptors along with dnotify also proved to be a problem when using removable media. Devices could not be unmounted since file descriptors kept the resource busy. Another drawback of dnotify is the level of granularity, since programmers can only monitor changes at the directory level. To access detailed information about the environmental changes that occur when a notification message is sent, a stat structure must be used; this is considered a necessary evil in that a cache of stat structures has to be maintained, for every new stat structure generated a comparison is run against the cached one. The inotify API uses fewer file descriptors, allowing programmers to use the established select and poll interface, rather than the signal notification system used by
dnotify dnotify is a file system event monitor for the Linux kernel, one of the subfeatures of the fcntl call. It was introduced in the 2.4 kernel series. It has been obsoleted by inotify, but will be retained for compatibility reasons. Its function is es ...
. This also makes integration with existing select- or poll-based libraries (like
GLib GLib is a bundle of three (formerly five) low-level system libraries written in C and developed mainly by GNOME. GLib's code was separated from GTK, so it can be used by software other than GNOME and has been developed in parallel ever sinc ...
) easier.


See also

* File Alteration Monitor (SGI) *
DMAPI Data Management API (DMAPI) is the interface defined in the X/Open document "Systems Management: Data Storage Management (XDSM) API" dated February 1997. XFS, IBM JFS, VxFS, AdvFS, StorNext and IBM Spectrum Scale file systems support DMAPI for Hie ...
*
kqueue Kqueue is a scalable event notification interface introduced in FreeBSD 4.1 in July 2000, also supported in NetBSD, OpenBSD, DragonFly BSD, and macOS. Kqueue was originally authored in 2000 by Jonathan Lemon, then involved with the FreeBSD Cor ...
(FreeBSD) *
FSEvents The FSEvents API in macOS allows applications to register for notifications of changes to a given directory tree. Whenever the filesystem is changed, the kernel passes notifications via the special device file /dev/fsevents to a userspace process ...
(macOS)


References


External links


Kernel Korner
an introduction to inotify by Robert Love (2005)
LWN Article on Inotify
watching filesystem events with inotify (partly out of date)

monitoring Linux filesystem events with inotify (6 September 2008).
Filesystem notification, part 1: An overview of dnotify and inotify
an LWN.net article by Michael Kerrisk (2014) {{Linux kernel Linux kernel features