perldoc -f alarm
#!/usr/bin/perl $lines=0; eval { local $SIG{ALRM} = sub { die "timeout\n" }; alarm( 5 ); while (<>) { $lines++; if ( $lines > 2 ) { alarm( 0 ); last; } } }; if ( $@ =~ /timeout/ ) { print "timed out with $lines lines\n"; } elsif ( $@ ) { print "died from some other random reason: $@"; } else { print "didn't timeout with $lines lines\n"; }
$ ( sleep 10 ) | perl 409100.pl timed out with 0 lines $ ( echo one; sleep 10 ) | perl 409100.pl timed out with 1 lines $ ( echo one; echo two; sleep 10 ) | perl 409100.pl timed out with 2 lines $ ( echo one; echo two; echo three; sleep 10 ) | perl 409100.pl didn't timeout with 3 lines
In reply to Re: tcpdump: setting a conditional timeout
by Anonymous Monk
in thread tcpdump: setting a conditional timeout
by intranetman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |