in reply to using $SIG as an IPC interrupt?
TIMTOWTDI ;-)
If your program is driven by an event loop, e.g. Tk, you should use that. If it isn't, you could roll your own using alarm - or ualarm() from Time::HiRes - and use a named pipe ( see mknod(1) or makefifo(1) ) for data transfer.
use IO::File; use Time::HiRes qw(ualarm); use strict; my $interval = 10000; # microseconds { my ($fh, $rout, $rin); my $pipe = '/path/to/pipe'; sub pipe_open { $fh = IO::File->new( $pipe , O_RDONLY | O_NONBLOCK) or die "Can't open $pipe: $!\n"; $rin = ''; vec($rin,fileno($fh),1) = 1; } pipe_open(); sub alarm_handler { # look if there's input at the pipe, non-blocking mode. my ($nfound, $timeleft) = select($rout=$rin, undef, undef, -1) +; if ($nfound) { print STDERR "data arrived at $pipe.\n"; while (my $line = <$fh>) { print $line; } close $fh; pipe_open(); } ualarm($interval); } } # set up signal handler $SIG{ALRM} = \&alarm_handler; ualarm($interval); # main program. sleep while 1; # the real program certainly does something more intere +sting
You control the latency tweaking $interval.
|
|---|