jbho has asked for the wisdom of the Perl Monks concerning the following question:
Output on 5.6:#!/usr/bin/perl -w use strict; use Time::HiRes qw( gettimeofday tv_interval ); print "$]\n"; my $elapsed = 0; my $start_time = [gettimeofday]; eval { local $SIG{ALRM} = sub { $elapsed = tv_interval( $start_time ); warn "alarm-timeout signal"; die; }; alarm(1); `ls -R / 2>/dev/null`; alarm(0); }; print "$@" if $@; print "$elapsed\n";
Output on 5.8:5.006 alarm-timeout signal at /home/jbho/bin/test_SIGALRM.pl line 15. Died at /home/jbho/bin/test_SIGALRM.pl line 16. 0.999504
Suggestion put out by member(s) of the community:5.008 alarm-timeout signal at /home/jbho/bin/test_SIGALRM.pl line 15. Died at /home/jbho/bin/test_SIGALRM.pl line 16. 109.948451
This solution would bypass the perl implementation for setting the signal.use POSIX ':signal_h'; my $alarm = 0; sigaction SIGALRM, new POSIX::SigAction sub { $alarm = 1 } or die "Error setting SIGALRM handler: $!\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to deal with safe signals in 5.8.0?
by Limbic~Region (Chancellor) on Jul 25, 2003 at 18:48 UTC |