Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

signal handler output

by morgon (Priest)
on May 17, 2018 at 13:01 UTC ( #1214736=perlquestion: print w/replies, xml ) Need Help??

morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

as a (contrieved) example that catches SIGINT consider this:

$SIG{INT} = sub { print STDERR "*"; }; while(1) { sleep(1); print STDERR "."; }
When I run this in bash and press Control-C to generate a signal I get the star printed, but I also get a "^C" in the output and I don't understand where this is coming from.

So the output looks like

.....^C*...^C*....^C*..
Where do these "^C"s come from? Is this the shell, the terminal or what? And is there a way to supress that from within a perl-script?

Many thanks!

Replies are listed 'Best First'.
Re: signal handler output
by hippo (Chancellor) on May 17, 2018 at 13:31 UTC
    Is this the shell, the terminal or what?

    It's the shell controlling the terminal. Here's what happens in bash if I interrupt both these commands:

    $ sleep 30 ^C $ stty -ctlecho; sleep 30 $

    As for perl, I expect IO::Stty might be able to do it but I've never used it for that.

      Not the shell, it's the tty driver itself. For linux, that would be n_tty_receive_char() in drivers/tty/n_tty.c. Upon receiving the control char, it optionally echoes it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2020-12-01 00:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?