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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |