Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: Monitor a file without polling (à la inotify in linux)

Is there a haskell library function to monitor a file without polling?

With polling i would do someting like this:

monitor file mtime handler = do
    threadDelay n -- sleep `n` ns
    t <- getModificationTime file
    if t > mtime
        then handler >> monitor file t handler
        else monitor file mtime handler

What I want is something like a blocking getModificationTime which will be woken up by the system. Is there something available?

I would be perfectly happy if it was available for posix systems only, but the more portable the better :-)

Edit: I know hinotify, but I'm on a Mac (that's why I mention POSIX).

like image 912
scravy Avatar asked Nov 30 '12 09:11

scravy


People also ask

What is inotify tool Linux?

inotify (short for inode notify) is a Linux kernel subsystem that notices changes in a file system (file/directory) and notifies those changes to applications. It is the base for many underlying command-line utilities that deal with file monitoring use-cases.

What is inotify watch?

Inotify Watch helps to keep track of the file changes under the directories on “watch” and report back to the application in a standard format using the API calls. We can monitor multiple file events under the watched directory using the API calls.


1 Answers

The kqueue package should do this: http://hackage.haskell.org/package/kqueue

like image 65
Sjoerd Visscher Avatar answered Oct 02 '22 21:10

Sjoerd Visscher