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

Re^4: Print inside SIGNALS

by pedrete (Sexton)
on Jul 16, 2018 at 19:43 UTC ( [id://1218609]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Print inside SIGNALS
in thread Print inside SIGNALS

This code does not work...

alarm 2; $SIG{ALRM} = \&Finish; my $a=<>; sub Finish { print "Timeout reached"; }

This code does not work either...

alarm 2; $SIG{ALRM} = \&Finish; while (1==1){}; sub Finish { print "Timeout reached"; }

So i guess many calls are not interrumptibles... am i right>?

Replies are listed 'Best First'.
Re^5: Print inside SIGNALS
by haukex (Archbishop) on Jul 16, 2018 at 20:20 UTC
    So i guess many calls are not interrumptibles... am i right?

    I don't think that's the problem here - see my reply to your nearly identical post here.

Re^5: Print inside SIGNALS
by ikegami (Patriarch) on Jul 17, 2018 at 11:22 UTC

    First snippet: <> can't be interrupted because there's no way to check <> for errors. However, the signal handler does get called once it returns.

    Second snippet: There's nothing to interrupt here, so the signal handler gets called immediately. However, since the program has no way of terminating the program cleanly, the message will never leave STDOUT's buffer to the underlying file system handle.

      First snippet: <> can't be interrupted because there's no way to check <> for errors. However, the signal handler does get called once it returns.

      At least on my machine (Linux), it seems to be the same buffering issue...

      $ perl -wMstrict -e 'alarm 2; $SIG{ALRM}=sub{ print "Timeout reached" };<>' ^C $ perl -wMstrict -e 'alarm 2; $SIG{ALRM}=sub{ print "Timeout reached\n" };<>' Timeout reached ^C $ perl -wMstrict -e 'alarm 2; $SIG{ALRM}=sub{ print STDERR "Timeout reached" };<>' Timeout reached^C

        No, "it didn't work" for you because you killed the program before the signal handler was called.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-25 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found