Updated: October 26, 2022

Add or update a watch for filesystem events associated with a path


#include <sys/inotify.h>

int inotify_add_watch( int fd,
                       const char *pathname,
                       int mask );


A valid file descriptor returned by inotify_init().
The path whose filesystem events you want to monitor.
A bitmask that specifies the events you want to watch. The bits include:
  • IN_ACCESS — the file was read.
  • IN_MODIFY — the file was written to.
  • IN_ATTRIB — the attributes of the file changed.
  • IN_CLOSE_WRITE — a file that was opened for writing was closed.
  • IN_CLOSE_NOWRITE — a file that was opened not for writing was closed.
  • IN_OPEN — the file was opened.
  • IN_MOVED_FROM — the file was moved or renamed away from the item being watched.
  • IN_MOVED_TO — the file was moved or renamed to the item being watched.
  • IN_MOVE — the same as (IN_MOVED_FROM | IN_MOVED_TO).
  • IN_CREATE — a file was created in a watched directory.
  • IN_DELETE — a file or directory was deleted.
  • IN_DELETE_SELF — the file or directory being monitored was deleted.
  • IN_MOVE_SELF — the file or directory being monitored was moved or renamed.

IN_ALL_EVENTS is a bitwise-OR of all the event types.

You can OR the following into the event type:

  • IN_ONESHOT — remove the watch during the generation of the first event.
  • IN_ONLYDIR — watch the pathname only if it's a directory.
  • IN_DONT_FOLLOW — don't dereference the pathname if it's a symbolic link.
  • IN_EXCL_UNLINK — don't generate events for children after they've been unlinked from the watched directory.
  • IN_MASK_ADD — add events to the watch mask (if one already exists) for this pathname, instead of replacing it.



Use the -l c option to qcc to link against this library. This library is usually included automatically.


The inotify_add_watch() function starts watching for filesystem events associated with the given path. For you to use this function, the filesystem event manager (fsevmgr) manager needs to be running.

Note: By default, inotify events are non-recursive, so you have to create a specific watch for each file or directory that you want to watch.

For an overview of inotify, see,0 in the Linux Journal, but note that there are differences between the Linux and QNX Neutrino implementations. Currently, only filesystems support inotify.


A watch descriptor, or -1 if an error occurred (errno is set).



Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes