Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.unix.questions,hp.unix Subject: Re: how do you watch for an incoming file Keywords: file directory unix Message-ID: <1989Nov29.042955.8217@virtech.uucp> Date: 29 Nov 89 04:29:55 GMT References: <5506@hplabsb.HP.COM> Organization: Virtual Technologies Inc. Lines: 40 In article <5506@hplabsb.HP.COM>, quan@hplabsb.HP.COM (Suu Quan) writes: > How do I write a C-program or shell script that will watch for > the presence of a new file in a certain directory. [example shell deleted] > But I would prefer a C-program or a script using a blocking command There is no way to sleep on a file being added to a directory. If you can't modify the software that is sending the file (to use some kind of IPC to tell your daemon that the file is there), the next best thing you could do is: set dir mtime var to non zero; set old mtime var to zero; forever loop { if( dir mtime var != old mtime var) { /* The dir has been modified, so look for new stuff...*/ old mtime var = dir mtime var } else { sleep(however long is ok); } stat(dir,to get current dir mtime var) } NOTE-> the code above was just off the top of my head, so there may be a typo, bug, mistake, or other such stuff. This way you are only stating the directory every x seconds (unless there is a file to process) and this shouldn't use up any measurable CPU as long as long as the sleep is > 1 second. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+