Name
inotify_add_watch - add a watch to an initialized inotify instanceSynopsis
#include <sys/inotify.h>int inotify_add_watch(intfd, const char *pathname, uint32_tmask);
![Python Python](https://image.winudf.com/v2/image/aW5vdHkuaW9zMTEuaW5vdGlmeS50aGVtZTExLm5vdGlmaWNhdGlvbl9zY3JlZW5fMl84aXlkNXFzbw/screen-2.jpg?fakeurl=1&type=.jpg)
$ readlink /proc/$(pgrep inotify)/fd/3 anoninode:inotify $ cat /proc/$(pgrep inotify)/fdinfo/3 pos: 0 flags: 00 mntid: 11 inotify wd:1 ino:357a sdev:700000 mask:fff ignoredmask:0 fhandle-bytes:8 fhandle-type:1 fhandle:7a0000 The sdev seems to be the major:minor device number combination, as seen in the output of lsblk, for example. Incron is an 'inotify cron' system. It works like the regular cron but is driven by filesystem events instead of time periods. It contains two programs, a daemon called incrond (analogous to crond) and a table manipulator incrontab (like crontab).
Description
inotify_add_watch() adds a new watch, or modifies an existing watch, for the file whoselocation is specified in pathname; the caller must have read permission for this file. The fd argument is a file descriptor referring to theinotify instance whose watch list is to be modified. The events to be monitored for pathname are specified in the mask bit-mask argument. Seeinotify(7) for a description of the bits that can be set in mask.A successful call to inotify_add_watch() returns the unique watch descriptor associated with pathname for this inotify instance. Ifpathname was not previously being watched by this inotify instance, then the watch descriptor is newly allocated. If pathname was already beingwatched, then the descriptor for the existing watch is returned.
The watch descriptor is returned by later read(2)s from the inotify file descriptor. These reads fetch inotify_event structures (seeinotify(7)) indicating file system events; the watch descriptor inside this structure identifies the object for which the event occurred.
Return Value
On success, inotify_add_watch() returns a nonnegative watch descriptor. On error -1 isreturned and errno is set appropriately.Errors
- EINVAL
- The given event mask contains no valid events; or fd is not an inotify file descriptor.
- ENOENT
- A directory component in pathname does not exist or is a dangling symbolic link.
- ENOMEM
- Insufficient kernel memory was available.
- ENOSPC
- The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource.