F_NOTIFY(2const)

🌸 F_NOTIFY(2const) β€” file & directory change notification 🌸

okay bestie, gather round, because this one is a const page for the fcntl(2) operation F_NOTIFY, and it's giving "your filesystem is gossiping about you and I'm the group chat" energy. it lives in section 2const of the Linux manual, and it's part of the Standard C library (libc, -lc), so you're covered.


✨ SYNOPSIS ✨

#define _GNU_SOURCE
#include <fcntl.h>

int fcntl(int fd, F_NOTIFY, int arg);

like yes, it's just fcntl() with a special command, but the vibe is so much more πŸ’…


πŸ’– DESCRIPTION πŸ’–

so here's the tea: F_NOTIFY gives you notifications whenever the directory that fd points at gets changed β€” or whenever any of the files inside it get changed. so basically you get to be nosy about a whole directory and it's completely legal, love that for you 🫢

the events you want to be notified about go in arg, and arg is a bit mask you build by ORing together zero or more of these bits:

heads up bestie: to even get these definitions you have to define the _GNU_SOURCE feature test macro before including any header files. no skipping that step, it's not optional, it's the entry fee πŸ’€

directory notifications are normally "one-shot" β€” meaning you fire it once and you're done, and the application must reregister to keep receiving further notifications. rude? a little. but alternatively, if you include DN_MULTISHOT in arg, then the notification stays in effect until you explicitly remove it. iconic behaviour honestly πŸ‘‘

a series of F_NOTIFY requests is cumulative β€” the events in arg get added to the set you're already monitoring, like stacking bracelets. and to disable notification of all events, you make an F_NOTIFY call with arg set to 0. clean slate, we love a reset 🌈

notifications arrive by delivering a signal. the default signal is SIGIO, but you can change that with the F_SETSIG operation to fcntl(). (note that SIGIO is one of the nonqueuing standard signals β€” so if you switch to using a real-time signal, that means multiple notifications can actually be queued to the process.) in that latter case, the signal handler receives a siginfo_t structure as its second argument β€” if the handler was set up using SA_SIGINFO β€” and the si_fd field of that structure contains the file descriptor which generated the notification. which is super useful when you've set up notification on multiple directories at once, because otherwise you'd have no idea which one was yapping πŸ¦‹

especially when you're using DN_MULTISHOT, you really should use a real time signal for notification, so that multiple notifications can be queued. fr fr, don't skip this one.

NOTE: new applications should use the inotify interface (available since Linux 2.6.13), which provides a much superior interface for obtaining notifications of filesystem events. see inotify(7). like, F_NOTIFY is your aunt's facebook, inotify is the group chat. just saying πŸ’œ


πŸŽ€ RETURN VALUE πŸŽ€

Zero. yes, zero. success is just... zero. no confetti, no fanfare, just zero.

on error, -1 is returned, and errno is set to indicate the error. sadness.


πŸ’€ ERRORS πŸ’€

  • see fcntl(2) β€” it's got the full drama.
  • ENOTDIR β€” fd does not refer to a directory. bestie. that's not a folder. that's not even giving folder. that's giving file πŸ™ˆ

⭐ STANDARDS ⭐

Linux. that's it, that's the standard. homegrown, no cap.


🧚 HISTORY 🧚

Linux 2.4. vintage, but make it functional.


πŸ‘‘ SEE ALSO πŸ‘‘


okay that's the whole page, and as always: this was brought to you by Linux man-pages 6.20, dated 2025-07-20, with love, glitter, and a concerning amount of fcntl() fangirling. go set up your notifications, bestie, and slay πŸ’…βœ¨πŸŒΈ

πŸ“¦ 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: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms