qbxk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to ensure that a process is generating output (it's supposed to be recording an audio stream). I've got 2 mechanisms to make sure that the recording process is running but recently i lost a few days of recordings when i didn't realize that the process WASN'T WRITING ANY OUTPUT. grrr

So, I'm making a cron that will opendir, and check that at least one file in my "scratch" directory has been modified recently. Thing is, apparently...readdir doesn't report files that are currently being modified.. wha?

here's my code currently:
open DIR, $ScratchDir or die $!; foreach my $file ( readdir(DIR) ) { print "$file\n"; }
this prints nothing! however, immediately after running that i produce this:
~/cron $ ls -l ScratchDir total 322944 -rw-r--r-- 1 unamechanged unamechanged 165347328 27 Aug 11:55 filen +amechanged.mp3
so see! there's a file in there, what gives? oh and, ahem, it should be noted that this is a Mac
~/cron $ uname -a Darwin WRUV-Studio.local 7.9.0 Darwin Kernel Version 7.9.0: Wed Mar 30 + 20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC Power Ma +cintosh powerpc

who's got my clue? thanks y'all

Replies are listed 'Best First'.
Re: readdir on files being modified
by borisz (Canon) on Aug 27, 2005 at 16:46 UTC
    You have to use opendir instead of open.
    Boris
Re: readdir on files being modified
by Anonymous Monk on Aug 29, 2005 at 06:53 UTC