LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-23-2008, 03:56 AM   #1
venkat_k
Member
 
Registered: Sep 2008
Posts: 36

Rep: Reputation: 15
inotify for recursive directory monitoring


Is there any way to use the inotify api for monitoring the directories recursively? (i.e adding a directory for watch should monitor inner directories also) or the only option is to add recursive watches, which is painful.

Is there any better api than inotify for doing this?
 
Old 12-23-2008, 09:49 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by venkat_k View Post
Is there any way to use the inotify api for monitoring the directories recursively?
The manual has a pretty precise answer to your question:
Quote:
Inotify monitoring of directories is not recursive: to monitor subdirectories under a directory, additional watches must be created.
 
Old 12-23-2008, 10:46 PM   #3
venkat_k
Member
 
Registered: Sep 2008
Posts: 36

Original Poster
Rep: Reputation: 15
Thanks for the reply.
Is there any API, better than inotify for this purpose?
 
Old 12-24-2008, 03:22 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by venkat_k View Post
Thanks for the reply.
Is there any API, better than inotify for this purpose?
Probably not. inotify is already an improvement over the previous dnotify.
 
Old 12-24-2008, 03:45 AM   #5
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

You say it's pain, but I guess the question is who gets the pain. You don't have to use many inotify watches, you can just add the subdirectories using inotify_add_watch, as well as adding/removing subdirectories when they are created/deleted.

If the kernel was to handle all the subdirectories, I guess it would get the pain. It's probably better that the userspace program gets the pain.

You can use some of the utility programs if you don't want to write the handeling of subdirectories, something like:

Code:
FILE *fp = popen("inotifywait -m -r -q /", "r");
 
  


Reply



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
Recursive directory search janel10 Linux - Newbie 2 08-26-2008 06:28 AM
recursive directory permissions confused_user Linux - Security 7 07-11-2006 06:02 AM
deletion of a recursive directory? captainnico Linux - Software 9 02-04-2006 05:52 AM
recursive directory traversal klfreese Linux - Newbie 2 08-20-2003 07:27 PM
recursive search of a string in a directory ?! realos Linux - Software 4 11-27-2002 04:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:16 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