Handling Filesystem Events with GCD

Posted by David Hamrick on

I wrote a post about how I use kqueue to monitor the filesystem for changes in my configuration files. This method has been working for me for some time now, but I’m glad that other readers pointed out a flaw in it. Mike Ash, of the Friday Q&A fame, noted that you can use GCD to monitor filesystem events. I believe that you should always work at the highest level of abstraction possible and this seemed like it would reduce the amount of code needed to achieve my goal, being notified when a certain file changes.

If you can target 10.6+ or iOS4+ you can use Grand Central Dispatch to handle filesystem notifications. Dispatch Event source can be used to monitor lot’s of different things such as sockets, signals, and processes. We will be using it to monitor a virtual filesystem node (vnode).

This method of monitoring a file is much simpler. We don’t need to create a custom class and it is much shorter in length. I will be switching away from using kqueue to using this method since I don’t need to maintain anything less than 10.6 or iOS4.


David Hamrick is a partner at Hamrick Software, the makers of VueScan, the worlds most popular 3rd party scanner software.