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:
DN_ACCESSβ a file got accessed, i.e. read. thinkread(2),pread(2),readv(2), and similar. someone peeked πDN_MODIFYβ a file got modified. that'swrite(2),pwrite(2),writev(2),truncate(2),ftruncate(2), and similar. glow-up gone different, honestly.DN_CREATEβ a file got created. coversopen(2),creat(2),mknod(2),mkdir(2),link(2),symlink(2), andrename(2)into this directory. new bestie just dropped πDN_DELETEβ a file got unlinked. that'sunlink(2),rename(2)to another directory, andrmdir(2). rip bozo πDN_RENAMEβ a file got renamed within this directory, viarename(2). same girl, new name β¨DN_ATTRIBβ a file's attributes changed.chown(2),chmod(2),utime(2),utimensat(2), and similar. she's reinventing herself.
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βfddoes 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