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

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

Replies are listed 'Best First'.
Re^7: Print inside SIGNALS
by ikegami (Patriarch) on Jul 17, 2018 at 16:18 UTC

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

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

      Have you tried the one-liners yourself? (I ran them on Ubuntu Linux, in case that makes a difference.)

      Are you saying you are observing different behavior than I am? If so, what is that behavior?

      If you're saying it's not a buffering issue, what do you think is causing the different behavior of the first two of my one-liners above?

        Let me be clear: Don't kill the program (e.g. by sending SIGINT to the program) and then complain that the rest of the program (e.g. the signal handler) doesn't run.