Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Handle-a-signal/Perl/handle-a-signal-1.pl
Normal file
21
Task/Handle-a-signal/Perl/handle-a-signal-1.pl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
my $start = time; # seconds since epohc
|
||||
my $arlm=5; # every 5 seconds show how we're doing
|
||||
my $i;
|
||||
|
||||
$SIG{QUIT} = sub
|
||||
{print " Ran for ", time - $start, " seconds.\n"; die; };
|
||||
$SIG{INT} = sub
|
||||
{print " Running for ", time - $start, " seconds.\n"; };
|
||||
$SIG{ALRM} = sub
|
||||
{print " After $arlm seconds i= $i. Executing for ", time - $start, " seconds.\n"; alarm $arlm };
|
||||
|
||||
|
||||
alarm $arlm; # trigger ALaRM after we've run for a while
|
||||
|
||||
print " ^C to inerrupt, ^\\ to quit, takes a break at $arlm seconds \n";
|
||||
|
||||
while ( 1 ) {
|
||||
for ( $w=11935000; $w--; $w>0 ){}; # spinning is bad, but hey it's only a demo
|
||||
|
||||
print ( ++$i," \n");
|
||||
}
|
||||
9
Task/Handle-a-signal/Perl/handle-a-signal-2.pl
Normal file
9
Task/Handle-a-signal/Perl/handle-a-signal-2.pl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use 5.010;
|
||||
use AnyEvent;
|
||||
my $start = AE::time;
|
||||
my $exit = AE::cv;
|
||||
my $int = AE::signal 'INT', $exit;
|
||||
my $n;
|
||||
my $num = AE::timer 0, 0.5, sub { say $n++ };
|
||||
$exit->recv;
|
||||
say " interrupted after ", AE::time - $start, " seconds";
|
||||
Loading…
Add table
Add a link
Reference in a new issue