views:

110

answers:

4

I like the inotify subsystem in Linux. However, I'm mainly a Windows user, so I was wondering if there's anything similar?

+1  A: 

I did a bit of searching, I seem to recall seeing something similar for Windows. There's FileSystemWatcher for .NET. Its mainly for NT or XP and forward.

Pharaun
+4  A: 

See the FindFirstChangeNotification API, or the .NET counterpart FileSystemWatcher

nos
A: 

http://jnotify.sourceforge.net/
or
this one from MS:
FileMon

Regards
Eugene

Eugene
+1  A: 

If you're using .net, use FileSystemWatcher. More info here: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

If you're using C, use FindFirstChangeNotification, FindNextChangeNotification, ReadDirectoryChangesW. More info here: http://msdn.microsoft.com/en-us/library/aa365261(VS.85).aspx

On OSX, the relevant api is the fsevents api.

They're all subtly different from one another, and they all have questionable reliability in edge cases. In general, you can't depend on these apis for a complete view of all changes 100% of the time. Most people using file system monitoring combine it with periodic scans to compensate for lost or incomplete information from the push api.

blucz
Can you please give some citation on the "questionable reliability in edge case for inotify?
Pharaun
If a consumer of a fs watcher api is slower at reading events than some other process is at generating them, the kernel either needs to hold up filesystem modifications in the other (possibly higher priority) process, or allow for unlimited growth of the buffer.inotify's buffer depth (as documented in the man page) is controlled by /proc/sys/fs/inotify/max_queued_events. Beyond this, you get a IN_Q_OVERFLOW notification--this is good, but you're still left in a situation where you may need to rescan from time to time.
blucz
Aha right, I was recently reading up on the queue. I think this edge case would depend on how many files you are monitoring and it also depends on if its critical to track all changes or if a few can be missed. But that's a good point. Thanks :)
Pharaun