Unix Programming - Directory Access Monitoring

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2005 > Directory Access Monitoring





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Directory Access Monitoring
Claudius Zingerli

2005-02-20, 6:20 pm

Dear NG,

Is there any way to get notified if someone moved a file into a
directory? I'm searching for something like:

handle=open(directory)
....
rc=select(handle);
if (rc>0) { do something }

My target is to write a program A that "listens" on a directory (like a
socket on a port). Another program B then moves a file into this
directory. Program A notices this and processes this file.

Does anyone know an API call or a solution for me? My program should run
at least on FreeBSD but Linux would also be nice. Is there any common
way to do that?


Thanks a lot!

Claudius

[dcoup readers: please ignore, my fault]
Michael B Allen

2005-02-20, 6:20 pm

On Sat, 19 Feb 2005 19:06:29 -0500, Claudius Zingerli wrote:

> My target is to write a program A that "listens" on a directory (like a
> socket on a port). Another program B then moves a file into this
> directory. Program A notices this and processes this file.


On linux look at /usr/src/linux/Documentation/dnotify.txt. FreeBSD
probably has something similar. There are also utility programs that will
execute a command in reponse to a directory changing. You might also
be able to simply open the directory of interest and fstat it every 5
seconds to see if mtime has changed. I've never done any of this however.

Mike
Heiner Steven

2005-02-20, 6:20 pm

Claudius Zingerli wrote:
> Dear NG,
>
> Is there any way to get notified if someone moved a file into a
> directory? I'm searching for something like:
>
> handle=open(directory)
> ...
> rc=select(handle);
> if (rc>0) { do something }
>
> My target is to write a program A that "listens" on a directory (like a
> socket on a port). Another program B then moves a file into this
> directory. Program A notices this and processes this file.
>
> Does anyone know an API call or a solution for me? My program should run
> at least on FreeBSD but Linux would also be nice. Is there any common
> way to do that?


I think there is no common (at least no standard) way to monitor
a directory for changes.

Since this is a common problem, there are different solutions, though.
You could e.g.

o use FAM (File Access Monitoring)
o Solaris event ports (starting with Solaris 10)

Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
SM Ryan

2005-02-20, 6:20 pm

Claudius Zingerli <msnews@zeuz.ch> wrote:
# Dear NG,
#
# Is there any way to get notified if someone moved a file into a
# directory? I'm searching for something like:

If you have kqueue on your system (BSD and perhaps ported to some Linuxes),
open the directory read-only, then set a kevent to watch the inode of the
open file. Changes to the directory will change the inode and be reported
back to you.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Quit killing people. That's high profile.
Markus Elfring

2005-02-20, 6:20 pm

> My target is to write a program A that "listens" on a directory (like a
> socket on a port). Another program B then moves a file into this
> directory. Program A notices this and processes this file.
>
> Does anyone know an API call or a solution for me? My program should run
> at least on FreeBSD but Linux would also be nice. Is there any common
> way to do that?


Would you like to use the free tool "File Alteration Monitor"?
http://oss.sgi.com/projects/fam/faq.html#what_is_fam


Claudius Zingerli

2005-02-21, 6:00 pm

Thanks for the many responses. I finally used kqueue and kevent in
FreeBSD and the fcntl-calls in Linux.


Claudius
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com