Monitor Filesystems with Inotify

I recently had the problem of writing an application that needed to get notifications when changes happened to a particular directory. Specifically, I was writing a Linux kernel mode driver (KMD), which would create entries in the /dev/ file system on connection of various devices, and I needed a user mode program that would detect these connections.

A collegue pointed me to Inotify, which solved this problem perfectly. In particular I used the C++ interface which can be downloaded along with an example code.

You can download the C++ interface for inotify. This compiles fine with g++ (e.g. g++ -c inotify-cxx.cpp)

And the example code for inotify (example.cpp). To use: compile this and link against the inotify-cxx object file.

The example code shows how you can easily get the type of event (e.g. create file, delete file etc.), and the filename of the file.

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)