Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Signal to a sleeping Perl program

by tybalt89 (Prior)
on Jan 20, 2020 at 00:49 UTC ( #11111616=note: print w/replies, xml ) Need Help??


in reply to Re: Signal to a sleeping Perl program
in thread Signal to a sleeping Perl program

Try using select instead of sleep - at least on linux it does not rely on ALRM, it's a single system call.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11111522 use warnings; # borrowed from choroba use feature qw{ say }; local $SIG{USR1} = sub { say STDERR "Signal 1 caught."; }; local $SIG{USR2} = sub { say STDERR "Bye!"; exit }; my $sum = 0; while (1) { $sum += $_ for 1 .. 100; say $sum; say STDERR scalar localtime, " Sleeping..."; select undef, undef, undef, 10; say STDERR scalar localtime, " Ready!"; }

I don't have a Solaris to test on, but this works as expected on my linux system.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11111616]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2021-02-27 19:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?