in reply to Leaky pipes?
The problem in your case is probably that at the low level, inside the perl interpreter, the die statement long-jumps over the cleanup code of the backtick operator where the pipes used to communicate with the slave process are closed.
There isn't an easy workaround. Maybe some module on CPAN would do it... though you should check that it doesn't use alarm internally.
A safe (untested) way to do it in perl is:
open my $pipe, "traceroute ... |" or die; my $start = time; my $buf = ''; while(1) { my $vin = ''; vec($vin, fileno($pipe), 1) = 1; if (select($vin, undef, undef, 1)) { sysread $pipe, $buf, 2048, length $buf or last; } last if time - $start > $timeout; } close $pipe; # traceroute output is in $buf now
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Leaky pipes?
by vancetech (Beadle) on Mar 22, 2006 at 19:44 UTC |