Thanks, that sounds like what I need, although I thought a I saw a more "direct" mechanism before.
I'm going to work on this in the next day or two before I close the question.
Main Topics
Browse All TopicsI am fairly certain I saw a function that allows a program to wait efficiently (no CPU time) until a change is made to a directory, but I can't remember its name. What is it called? I just need to be pointed in the right direction.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If you do find another way I would be interested. As mentioned, we modified the kernel to include select() functionality precisely because we couldnt find another method. Other pieces of information that may be useful.
o If I recall correctly you call getdents() with the 'fd' and it returns struct dirents *. You may have to call it
multiple times if the number of entries hit some magic number
o I beleive you need to lseek(fd, 0, 0) after your done with getdents().
o If getdents isnt in the libc you can you call syscall3(GETDENTS, ....)
o I think dnotify is available only in kernel version >= 2.4.0
Best of luck
Sorry, I didn;t beack to this sooner. I got pulled onto another project.
I looks like this was the "function" (mechanism) I had seen before. Unfortunately it won't work very well for my case due to the asynchronous nature of the signals. (We'll have lots of threads watching for changes on lots of directories and so I want to handle it with a single signal and single signal handler, that then looks at the file descriptor to see what directory changed, but that is risky in a multi-threaded program because I don't think I can safely lock mutexes within a signal handler. (The thread might lock the mutext, then the signal handler in that thread might try to lock the mutex and we get deadlocked.) I haven't quit figured out what I'm going to do.
What version of the kernel are you using? Depending on your requirements
we handled this in two ways
1) Dont flip a mutex in a sighandler. Simply let the signal pull the thread out
of the pause()/sleep() statement. Then rescan the directory. Occasionally you get
a false negatives but this is better than continually scanning.
2) We implemented select() on some filesystems inside the kernel. (Tested on
EXT2 and reiserfs) for 2.4. I could send you the patch and you play with it.
Depending on how exciting it is I would be willing to help you.
Take care. I hope you get a good solution.
NJK (experts-exchange@manse.ca
No offense to you as a programmer--really--but I don't think I could get anyone here to trust a patch to the kernel. (although that would obviously be the best approach to handling this sort of thing from the programmer's point of view.)
the thread's aren't using pause()/sleep() they are waiting on condition objects. I was hoping to signal the condition from the signal handler, but it has to figure out what thread/condition object to signal.
I you have any ideas, I'd be happy to "ask" you another question to give you the points.
Business Accounts
Answer for Membership
by: njk123Posted on 2003-09-23 at 14:50:01ID: 9416503
The only way in Linux to wait for events on a directory is to use the F_NOTIFY signals. After setting the fcntl() a signal is generated everytime you ACCESS/CREATE/MODIFY/... a file. Depending on the flag. There was a patch submited to linux-kernel in 2001 (by your truly) that allowed programmers to use select() and poll() on directory filedescriptors, but that went nowhere.
Obviously this isnt real code. If you need something more syntactically correct I am sure somebody could ablige.
for example
void sighandler(int sig, siginfo_t *spI, void *buf)
{
do something with spI->si_fd;
}
main()
{
myAct.sa_sigaction = sighandler;
sigaction(SIGIO, &myAct, NULL);
fd = open("/my/directory/name",
fcntl(fd, F_NOTIFY, DN_MODIFY|DN_CREATE);
for(;;){ pause(); /* do something */}
}
After writing this .... I also found information in
/usr/src/linux/Documentati
Good luck