linux system call to detect changes in a directory
Can someone help me to know how to do a program that detect changes in a directory ?
I need to do a program that stay in "idle mode" until a occurency of any changes in directory monitored by the program. Thanks. |
Vixe!!! Acho que era baum ocê usá um daemon, não?
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... HTH, vfs |
(Eu nao gostaria de fazer assim)
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 ? thanks, |
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.
Code:
#include <stdio.h> |
Luciano, do you study at USP?
vfs |
All times are GMT -5. The time now is 04:56 AM. |