linux system call to detect changes in a directory
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I think you need a daemon to log the disk activity and check if something was changed.
Check 'stat()' and friends (man stat). Something like a daemon saves log with disk contents list now. Then it runs within the next 5 seconds, f.e., save new log, then compare the old with the new... I don't know, just "vaporware" tinkering...
I would not like to develop the program, using internal timing embbed into it.
I'm looking for ways to use API (system call) like as FindFirstChangeNotification() / FindNextChangeNotification() / Wait() from Windows SDK, where the Operating System notify the program on any changes (like as file creation, file change, etc...) and the applicatin stay in idle, not using resources of system while waiting for "events".
I have another sample on TCP/IP:
In sockets we use select() to put the program in idle until the occurency of events as timeout (previous configured) or data traffic, etc ...
Do you know way to monitor directory changes in the similar way ?
I'm not aware of a way to do it how you want. I don't know of a call like Windows has. The only way I can think to do it is with a daemon like vfs suggested. Here is a very hacked together example. The program started out in C, but changed to C++ so I could use the stl map class. The daemon code is commented out so you can see the output. Some logging would have to be added for daemon mode.