Greetings ye Monks.
I have a loop that sleeps at the end and I want to make the thing bail out if the whole loop takes too long. The obvious solution:
alarm 10 while ( ! $done ) { $done = is_it_done_yet(); sleep 1; }
... is bad because perlfunc says:
It is usually a mistake to intermix "alarm" and "sleep" calls. ("sleep" may be internally implemented in your system with "alarm")
So what's the "right" way to do this?
Do I want to fork off a watcher process? Is there a simpler way? If there isn't a simpler way, is there a good CPAN module that handles this?
For background: I'm writing an apache log rotater. I want to compress the files once apache has stopped writing to them, which is what is_it_done_yet() is analogous to. My script checks to see if it can start compressing by using lsof (Unix::Lsof) and compresses them using gzip if it can. If lsof or gzip wander off and never return, I want to have some way to abort the whole thing.
Thanks!
--Pileofrogs
In reply to Alternatives to Mixing Alarm and Sleep by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |