1

I am developing my program on Linux, is there a programmatic way to detect when another application creates/copies a file under/to a specific folder. I want to detect the new file as fast as it is created and I would like to process the file.

As far as I researched I can accomplish this using inotify. Are there any better alternatives?

4
  • 2
    You seem to already know the answer, which is indeed to use inotify. Commented Sep 24, 2012 at 11:25
  • 1
    What's wrong with inotify? It's great. And it fits into your existing epoll multiplexer loop (which I hope you have). Commented Sep 24, 2012 at 11:28
  • 3
    Nothing is wrong with it, I just wanted to see what other options I have, before getting my hands dirty with it. Commented Sep 24, 2012 at 11:30
  • is inotify scalable? IS there not a limit on the number of watches? Commented Dec 3, 2021 at 21:44

3 Answers 3

1

inotify is the proper API provided by the Linux kernel. Your toolkit may have convenience on top of it, e.g. KDirWatch from libkdecore, but that uses inotify internally.

Using API from a toolkit is a good idea when your program is cross-platform.

Sign up to request clarification or add additional context in comments.

Comments

1

http://www.highscore.de/boost/dir_monitor.zip on http://en.highscore.de/cpp/boost/asio.html is a cross-platform C++ Boost solution, though I haven't tried it yet.

http://boost.2283326.n4.nabble.com/ASIO-file-monitoring-help-td4645105.html has code using it that is wrong, the fix looks to be to make a few more objects the author assumed could be temporary permanent instead.

Comments

1

http://man7.org/linux/man-pages/man7/fanotify.7.html is another option

This is a nice article which sums all methods http://www.lanedo.com/filesystem-monitoring-linux-kernel/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.