how does Linux detects about any file modifications in a directory or its sub dir
I am working on a C++ application to monitor any changes in a Linux directory recursively. I am using inotify to monitor any file modification on Dir recursively. I know inotify cannot detect any changes in sub directory so i am adding a watch to each sub-directory i find while traversing the directory tree.
But I do not get any notifications about any modification after 2 levels inside my directory tree. Can someone provide me a C/C++ reference code to monitor a directory in Linux recursively. Also how does Linux monitor file changes in a Dir recursively. Does it use inotify internally or some other subsystem. |
Look at the source of inotifywait? It's written in C.
Code:
apt-get source inotify-tools |
Depends on why you aren't getting notifications...
There is a limit to how many watch notifications you can ask for. http://monodevelop.com/Inotify_watches_limit In the general case though, Linux doesn't use notifications. These are just a convenience function for users. Unfortunately, it isn't sufficiently general (as in using it to detect new/modified/deleted files and queuing for a backup update...) since the lists are maintained in the kernel... and a directory hierarchy may have millions... The default limit indicated in the article above is 8192. More than that get dropped. |
All times are GMT -5. The time now is 12:23 AM. |