LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 09-10-2014, 06:36 AM   #1
rex1254
LQ Newbie
 
Registered: Aug 2014
Posts: 15

Rep: Reputation: Disabled
inotify -cannot add a watch to newly created directory after few levels in a directoy


I am using inotify on Linux to monitor a directory. My directory has 50 sub-directories and my directory tree is 20 level deep. I am able to monitor directory and all its sub directories till this point. I using C++ STL vector to save each directories path and their respective watch descriptor. When i add 8 or 10 new directories recursively i.e. add new 8-10 new level, i get notification about any event till 28th or 30th levels inside the directory tree. If i create a new directory inside 28th or 30th level than i do not get any notification.

Has any body faced this problem.

Last edited by rex1254; 09-10-2014 at 07:11 AM.
 
Old 09-10-2014, 01:20 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
I'm not clear on your directory structure. Are you exceeding the watch limit?
Code:
$ cat /proc/sys/fs/inotify/max_user_watches 
8192
Also, I noticed in your other thread that you are using Qt ( qDebug() ). Have you tried using QFileSystemWatcher?

Last edited by norobro; 09-10-2014 at 09:05 PM. Reason: Added QFilesystemWatcher link
 
Old 09-11-2014, 02:51 AM   #3
rex1254
LQ Newbie
 
Registered: Aug 2014
Posts: 15

Original Poster
Rep: Reputation: Disabled
Yes you are correct about Qt. I did think about using QFileSystemWatcher but while i seraching for a solution I found that QFileSystemWatcher internally uses inotify to monitor directory changes. Using QFileSystemWatcher will only consume a little more memory. I want to monitor a large directory structure so using QFileSystemWatcher will cost me more memory if the directory structure is very large.
Also in my error check I am checking for ENOSPC that is return by inotify_add_watch(..) if maximum watch limit is exceeded;
So if I am exceeding the maximum watch limit then I will be notified by my application but i do not get maximum watch limit. My application just stops adding a new watch after i add few new level in my watch directory.

Below is my directory structure

LEVEL 1 watch directory
|
--------------------- ...... ---
| | |
LEVEL 2 dir1 dir2 ...... dir15
|
--------------
| |
LEVEL 3 dir1_1 dir1_2......
. .
. .
. .
. .
. .
|
--------------
| |
LEVEL 30 dir1_30 dir1_30...
 
Old 09-11-2014, 02:57 AM   #4
rex1254
LQ Newbie
 
Registered: Aug 2014
Posts: 15

Original Poster
Rep: Reputation: Disabled
Watch directory
|
|`````````````````|......|-------------> LEVEL 1
dir1 dir2 dir15
|
|`````````````````|--------------------> LEVEL 2
dir1_2 dir1_2
.
.
.
.
|
|`````````````````|--------------------> LEVEL 30
dir1_30 dir1_30
 
Old 09-11-2014, 02:59 AM   #5
rex1254
LQ Newbie
 
Registered: Aug 2014
Posts: 15

Original Poster
Rep: Reputation: Disabled
Watch directory
--------|
|`````````````````|..........|-------------> LEVEL 1
dir1-------------dir2------dir15
--|
|`````````````````|--------------------> LEVEL 2
dir1_2----------dir1_2
.
.
.
.
---|
|`````````````````|--------------------> LEVEL 30
dir1_30-------dir1_30
 
Old 09-11-2014, 12:46 PM   #6
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
You could try monitoring the directory with inotify-watch from inotify-tools to see if the problem is with your code or inotify.

If you post your code somewhere, I'll be happy to take a look.
 
  


Reply

Tags
c++, filesystem, inotify, linux



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
inotify to watch a directory then print and move algreig Linux - Newbie 4 05-25-2012 10:14 AM
Defining home directory of a newly created user?? ggarrette Linux - Newbie 4 07-01-2008 02:47 PM
Can't access newly created directory DaftDave Linux - Newbie 4 06-27-2008 04:00 PM
Trying to Add Users to Newly Created Group (Red Hat version) Linux_Enabled Red Hat 1 07-31-2007 10:13 PM
Newly created File/directory permissions? redrobin77 Fedora 3 11-14-2005 04:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:22 AM.

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