inotify_init(2)

๐Ÿ’– inotify_init โ€” it's in the inotify_init(2) era, bestie ๐Ÿ’–

okay so this is a page from the System Calls Manual, and we're talking about initializing an inotify instance. Get comfy ๐Ÿซถ


โœจ NAME โœจ

inotify_init, inotify_init1 โ€” initialize an inotify instance

No cap, that's literally the whole job. You're building a little inotify baby. ๐Ÿ‘‘


๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc) โ€” the classic. The OG. We stan.


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <sys/inotify.h>

int inotify_init(void);
int inotify_init1(int flags);

Look at those two. Sisters. One of them takes a flags argument, one of them is a no-argument girlie who keeps it simple. Both iconic. ๐Ÿ’…


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

Wanna know the whole big picture of the inotify API? Go read inotify(7). That's the vibe overview, this is the specific-girl page.

inotify_init() initializes a new inotify instance and returns a file descriptor associated with a new inotify event queue. That's it, that's the whole plot. You get a fd, the fd has its own event queue, you go watch files with your new bestie. ๐ŸŽ€

Now โ€” if flags is 0, then inotify_init1() is doing literally the exact same thing as inotify_init(). Same girl, different outfit.

But! You can bitwise OR the following values into flags to get different behavior, and this is where it gets juicy:

  • IN_NONBLOCK โ€” sets the O_NONBLOCK file status flag on the open file description (peep open(2) for that concept) that the new file descriptor refers to. Using this flag saves you extra calls to fcntl(2) to achieve the same result. Likeโ€ฆ why do two steps when one step slays? ๐Ÿ”ฅ
  • IN_CLOEXEC โ€” sets the close-on-exec (FD_CLOEXEC) flag on the new file descriptor. If you wanna know why that's useful, go read the description of the O_CLOEXEC flag in open(2). Trust, it's a whole thing. ๐Ÿ’œ

๐ŸŽ€ RETURN VALUE ๐ŸŽ€

On success, these system calls return a new file descriptor. Yay! New fd! ๐ŸŽ‰

On error, -1 is returned, and errno is set to tell you what went wrong. It's giving "the universe is explaining itself to you." ๐Ÿ˜ญ


๐Ÿ’€ ERRORS ๐Ÿ’€

Every one of these is a little heartbreak, so let's go through the whole roster, fr fr:

  • EINVAL โ€” only from inotify_init1(). An invalid value was specified in flags. Girl. You put something illegal in flags. ๐Ÿ™ˆ
  • EMFILE โ€” the user limit on the total number of inotify instances has been reached. You maxed out your personal inotify allowance. ๐Ÿ˜ญ
  • EMFILE โ€” the per-process limit on the number of open file descriptors has been reached. Same error name, different flavor of too-much. Yes, it shows up twice. It really said "I contain multitudes." ๐Ÿ’€
  • ENFILE โ€” the system-wide limit on the total number of open files has been reached. Not just you โ€” the entire system is booked and busy. ๐Ÿ”ฅ
  • ENOMEM โ€” insufficient kernel memory is available. The kernel is tired. No thoughts, head empty, out of memory. ๐Ÿงš

๐ŸŒˆ STANDARDS ๐ŸŒˆ

Linux.

That's the standard. That's the list. Periodt.


๐Ÿ‘‘ HISTORY ๐Ÿ‘‘

Baby photos of the two functions:

  • inotify_init() โ€” Linux 2.6.13, glibc 2.4. An elder. Respect her. ๐Ÿซถ
  • inotify_init1() โ€” Linux 2.6.27, glibc 2.9. The younger sister who showed up with a flags argument and changed the game. โญ

โญ SEE ALSO โญ

Go be nosy, bestie:

iykyk โ€” that's the whole friend group right there. ๐ŸŒธ


okay and finally, the little sign-off: this was pulled from Linux man-pages 6.20, dated 2026-02-08, and the original page was inotify_init(2) โ€” so if you ever need to cite your sources for the group chat, now you have them. mwah ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: GPL-2.0-or-later
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms