What OS are you on? If it's a reasonably modern Linux, you could use Linux::Inotify. It does exactly what you want: The perl code gets prodded when specified files change.

How are you checking the file for changes? If you're checking the modify time, the file system needs to have a granularity smaller than the loop, I.E. if your fs only keeps track of modify time in seconds, a loop smaller than 1 second is pointless.

Another OS side option would be a fifo, AKA named pipe. This is a thing that looks like a file to your processes, but it actually takes the writes of one process and hands them as reads to another process. You need to use select again, for this to work. This is really no different than the other pipe suggestions except you wouldn't have to modify your C code.

When you say it doesn't sleep, but does stuff in the background, are you saying it never has to wait for new data? IE, the new data comes in so fast your script can't keep up? Or are you saying it does other unrelated jobs while it waits for new data? What kind of data is this? Why do you want to react to it faster than 200ms if your script is already busy? Does new data stream in in large volumes, or is it a rare event that signals the script should change what it's doing?


In reply to Re: using $SIG as an IPC interrupt? by pileofrogs
in thread using $SIG as an IPC interrupt? by bobbob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.