------------------ perl_alarm_test.pl -------------------- #!/usr/bin/perl my $time = shift; defined $time or $time = 5; $SIG{ALRM} = sub { $last = 1; }; $SIG{INT} = sub { $last = 1; }; alarm $time; $last=0; $index=0; while ($last eq 0) { sleep 1; $index=$index+1; print "$index\n"; } $SIG{INT} = undef; exit; -----------------------------------------------------------