# Somehow put main thread to sleep here…
CFRunLoopRun();
There you go.
CFRunLoopRun()
spins the run loop for the current thread (in this case, the main thread). Since you’ve attached an FS event stream to the main run loop, your FS events will be processed by this run loop and, consequently, your callback function will be called. The run loop will keep spinning until you call CFRunLoopStop()
(if you call it).
You need to decide how to handle program termination, though. Cocoa applications can use the convenient -[NSApplicationDelete willTerminate:]
method to perform cleanup operations. Since you are not using Cocoa, you’ll have to roll your own, maybe by using atexit(3)
or signal(3)
and using ⌃C to quit the program.