in reply to using $SIG as an IPC interrupt?

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?

Replies are listed 'Best First'.
Re^2: using $SIG as an IPC interrupt?
by bobbob (Acolyte) on Aug 21, 2008 at 19:46 UTC
    Right now I am polling the file every 200ms and looking for the contents to change (ie. to be appended to).

    The Perl application includes a substantial Tk GUI interface component, and it also writes files to send messages to other applications, is doing some computations for the GUI interface, etc. Its doing other things but when a message comes in from this C application that is the 'high priority' task and should be processed as soon as possible.

    Data does not stream in large volumes per se, but when new data is there it is highly desireable to process it as soon as possible.

      You should seriously consider multiple threads or multiple processes. This is the kind of thing they do really well.

      Did you say what OS you're on? Can you use Inotify?

      Since you are using Tk, you could hook in POE's POE::Component::DirWatch. The DirWatch session is given time slices within the Tk event loop, so unless the GUI is clogged it should deliver directory changes fairly quick. For immediate processing you would use signals and a signal handler.