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

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

Replies are listed 'Best First'.
Re^8: Print inside SIGNALS
by haukex (Archbishop) on Jul 17, 2018 at 18:14 UTC
    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.

        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.

        I didn't.

        $ perl -e 'sleep 10;print"World\n"' | perl -e '$x=time; $SIG{ALRM}=sub{print"Hello ";$y=time}; alarm 2; $z=<>; print $z,$y-$x," ",time-$x,"\n"' Hello World 2 10

        On my system, all of the above output does not happen until after 10 seconds. See above.