Re: 'file changed'-event



Michael Goerz <news2132@xxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:
> Hi,
>
> I'm trying to execute a sub whenever a certain file on the disk changes.
> Currently, I'm doing this with an infinite loop that checks the modify
> time (stat("$file"))[9]. While this works in principle, the infinite
> loop drives the CPU crazy and speeds up the fan (very annoying).
>
> Can I implement this with an event-based approach that doesn't drive up
> my CPU? How?

Unless your file system supports events you'll ultimately have to watch
the file. However, doing so in a tight loop is useless. Presumably the
file system's resolution is one second, so you should only stat the file
once a second. If you don't need maximum resolution make the intervals as
long as reasonable. That will make the load tolerable.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
.



Relevant Pages

  • Re: Wrong-but-not-incorrect code
    ... >> Can you, by artifical construction or actual experience, come up ... >> correct code that performs the intended task? ... > that I later decided needed to be a for loop. ... the broken "Reply" link at the bottom of the article. ...
    (comp.lang.c)
  • Re: Daughters Wedding Experience
    ... > Also there are a lot of situations in photography where a little luck ... The bottom end (shoot the grandkids, ... The short feedback loop will cause a few of them ... "To announce that there must be no criticism of the President, ...
    (rec.photo.digital)
  • Re: Building small 80 meter loop antenna
    ... a simple gamma feed (without a capacitor) at the bottom of the loop. ... so finding an optimum match should not be that ...
    (rec.radio.amateur.antenna)
  • Re: formatting inputbox
    ... change your loop to a For Next loop and loop backward from the bottom. ... Dim rCell As Range ... CountRows = rCell.Offset.Row ...
    (microsoft.public.excel.programming)
  • Re: UML fails to locate address space
    ... still need the loop looking for the bottom of the address space in ... and it makes sure the loop is exercised. ... Work email - jdike at linux dot intel dot com ...
    (Linux-Kernel)