logoalt Hacker News

lzhgusappyesterday at 8:08 PM2 repliesview on HN

Nice writeup. I work on native macOS utilities and have dealt with file monitoring quite a bit. kqueue is reliable but the per-file descriptor requirement can get tricky when you need to watch large directory trees.

For anyone looking at this space, FSEvents is the higher-level alternative Apple provides. It watches directory-level changes without needing a file descriptor per file, which scales better for broad monitoring. But kqueue gives you more granular control, like detecting attribute changes or renames specifically, which FSEvents sometimes lumps together.

In practice I've found a combination works well: FSEvents for broad directory watching to catch that something changed, then kqueue for targeted monitoring of specific files you care about.


Replies

saagarjhatoday at 12:51 AM

NSFilePresenter is an even higher level API and the one I typically recommend to people since it’s very easy to use

feznyngtoday at 12:31 AM

Can you treat kqueue as infallible? I've found FSEvents sometimes drops events at high volume (unless I'm misunderstanding how to use it).

show 1 reply