Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-04-2014, 03:10 AM   #1
LQ Newbie
Registered: Aug 2014
Posts: 15

Rep: Reputation: Disabled
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.
Old 09-04-2014, 03:54 AM   #2
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,292

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Look at the source of inotifywait? It's written in C.

apt-get source inotify-tools
Old 09-04-2014, 10:11 PM   #3
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,702

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
Depends on why you aren't getting notifications...

There is a limit to how many watch notifications you can ask for.

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.


c++, filesystems, linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] NIS Client error: Could not chdir to home directory /home/chacha: No such file or dir gauravgoel1989 Linux - Server 8 09-20-2013 04:42 PM
Log all file and directory modifications Find Linux - Security 3 12-04-2012 03:32 AM
how does linux detects a file type.... whether it is .mp3 or .jpeg or anything..... kkmageshcse Linux - Newbie 7 09-02-2008 02:37 AM
how to copy a file to a directory ,where file and dir are sent as args to a function? wrapster Programming 1 06-08-2008 07:00 AM
Yast detects my winmodem/Directory cleanup? Soulful93 Linux - Newbie 3 03-25-2004 07:11 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration