Suppose I have a program monitoring a pre-defined set of files for their creation, modification, or deletion. If one of those three events occurs on one of the files, I want to call a piece of code in response. Presently the code sits in a loop with a sleep at the bottom and just checks all the files using stat, etc. Is there a way to do this with callbacks so I don't have to waste CPU cycles looping? I expect the events to be very sparse in time so a callback is preferred. I see kevent gives a mechanism for monitoring modifications on an fd, but I'm not sure how it could be used to monitor for files not yet created. Should I just monitor the directory entry where I expect the file to be created? Any advice welcome.
BTW this is FreeBSD 7 (if it matters).
BTW this is FreeBSD 7 (if it matters).