Version française
Home     About     Download     Resources     Contact us    
Browse thread
How to monitor a specific file for changes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Gordon Henriksen <gordonhenriksen@m...>
Subject: Re: [Caml-list] How to monitor a specific file for changes
On Oct 22, 2007, at 15:03, Orlin Grigorov wrote:

> This time I've done my research, but still I cannot find a good  
> answer.   Basically, I need to make a little ocaml process, which  
> runs in the background and monitors a specific file for changes.    
> When a change occurs, I want it to back-up a copy of the version of  
> the file at that moment.    So, what I need is to set some signal  
> or event, which will happen every time that file is changed.

Orlin,

If you wish to be cross-platform, you'll likely need to devise an  
abstract interface to smooth over the variances between platforms.  
You've plenty of Linux pointers already.

On Windows, use FindFirstChangeNotification[1].

On Mac OS X and BSD, use kqueue[2]. kqueue was introduced in Tiger,  
and is one of the supporting technologies for Spotlight. To support  
Panther and earlier, you'll need to weak link[3] with kqueue. If  
kqueue is unavailable or not supported on the filesystem in question,  
you can fall back to polling modification times.

Polling modification times is simple and highly portable; many Java  
programs (for instance, Eclipse) support file monitoring using this  
technique. It may be worth considering using it exclusively, at least  
to get up and running.

— Gordon


[1] http://msdn2.microsoft.com/en-us/library/aa364417.aspx
[2] http://developer.apple.com/documentation/Darwin/Reference/ 
ManPages/man2/kqueue.2.html
[3] http://developer.apple.com/technotes/tn2002/tn2064.html