Go Back   UNIX Socket FAQ > UNIX Platforms > Files and Directories

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2009, 09:47 PM
Loco Loco is offline
Old administrator
 
Join Date: Jun 2002
Location: Colombia
Posts: 351
Default Detecting new files on directory

Hello everybody,

Do you know if it's possible to detect when some new files are put into a directory? I mean, is it possible to monitor a directory in order to do something when a new file is added, or modified, or whatever in that directory?

What do I want to do? I want to monitor a directory where users can put files via FTP, and whenever a new file arrives, I want to start processing it. I am currently using a cronjob that executes every 5 minutes or so, but that's a lousy solution because our users are transferring the files not that often. However, I cannot use a longer period of time because the users expect their files processed soon enough.

I don't want to waste resources running the cronjob, and I want to give the users a good experience.

Any suggestions are welcomed...

Regards,

HLR
Reply With Quote
  #2  
Old 11-11-2009, 01:09 AM
i3839 i3839 is offline
Oddministrator
 
Join Date: Jun 2003
Location: Amsterdam
Posts: 2,002
Default

On Linux you can use dnotify: F_NOTIFY with fcntl(2). It's a bit icky, but it
does what you need. With newer (2.6.13) kernels you can also use inotify(7).

An alternative is to use a file monitoring library or daemon like Gamin or FAM,
which is more portable and falls back on polling if no suitable notification
method is available.
Reply With Quote
  #3  
Old 11-11-2009, 02:58 PM
Loco Loco is offline
Old administrator
 
Join Date: Jun 2002
Location: Colombia
Posts: 351
Default

Quote:
Originally Posted by i3839 View Post
On Linux you can use dnotify: F_NOTIFY with fcntl(2). It's a bit icky, but it
does what you need. With newer (2.6.13) kernels you can also use inotify(7).
Hello i3839,

Thank you. I checked but unfortunately inotify is not available on the system, and unfortunately I cannot make any modifications to the system.

dnotify actually works, and it's quite fine for what I want to do.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:45 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.