Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Signal to a sleeping Perl program

by jerryhone (Sexton)
on Jan 19, 2020 at 23:38 UTC ( #11111613=note: print w/replies, xml ) Need Help??

in reply to Signal to a sleeping Perl program

Thanks everyone for responses. The OS I'm actually working on is Solaris, and I've had various thoughts about how to forcefully break into the loop, but the consensus here seems to be that the signal handler should work - it just doesn't!

Replies are listed 'Best First'.
Re^2: Signal to a sleeping Perl program
by tybalt89 (Monsignor) on Jan 20, 2020 at 00:49 UTC

    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; # 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.

Re^2: Signal to a sleeping Perl program
by LanX (Sage) on Jan 19, 2020 at 23:43 UTC
    Maybe you should have replied earlier, most of us thought you are on Windows.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2023-06-05 01:08 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (22 votes). Check out past polls.