A deep dive into using the kqueue kernel event notification interface on macOS to detect file changes. Starting with C code to explain kqueue data structures (kevent, EVFILT_VNODE, NOTE_WRITE, EV_CLEAR), the post then implements a file watcher in Go using the unix package. It covers watching named files, watching directories recursively, handling new file creation events, and important details like setting O_CLOEXEC to prevent file descriptor leaks into child processes. The author also compares kqueue to polling and FSEvents, noting kqueue's fd-per-file limitation for large directory trees.

11m read timeFrom vegardstikbakke.com
Post cover image
Table of contents
# kqueue data structures# Watching named files# Watching a directory# Implementing in Go# Final thoughts

Sort: