'^U does not kill despite stty claims

problem: ctrl+U will not kill my terminal program.


details: Here are my results from ssty --all:

speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

As you can see, it describes the available signal interrupts:
^C = intr
^ \ = quit
^U = kill
etc ...

Here is an infinitely running program:

int main (){while(true){}}

ctrl+C works

$./main                                                             
^C
$

ctrl+\ works

$./main                                                           
^\[1]    6331 quit (core dumped)  ./main
$

ctrl+U does not work.
Why can't I kill a terminal program this way?

I could of course find the process id and run kill -9 <PID>,
but I want the shorthand to work.


I'm on Ubuntu:

lsb_release --all 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty

Here are my terminal specs, but I've tried other terminals (probably not relevant)

gnome-terminal --version                                           
GNOME Terminal 3.6.2

It didn't work on xterm either. I've also tried different shells:
sh, bash, ans zsh.

What could the problem be? Where should I look now?



Solution 1:[1]

kill in stty's output refers to the kill-line character, that is, pressing ^U erases to the beginning of the line.

The characters that send an interrupt signal are intr, quit, susp, and on some systems (not on Linux IIRC), dsusp.

Solution 2:[2]

To implement such a thing, you would have to add another signal, say VPKILL and PKILL_CHAR for process kill as opposed to the existing VKILL and KILL_CHAR in include/linux/tty.h; a new else if clause to drivers/tty/n_tty.c in the Linux source, and modify any other necessary header and driver files accordingly. I suspect this is easier said than done, as this logic is baked into Linux at a very low level, and there may well be assumptions in other parts of the kernel that will cause loss of stability and Heisenbugs.

    if (L_ISIG(tty)) {
            if (c == INTR_CHAR(tty)) {
                    n_tty_receive_signal_char(tty, SIGINT, c);
                    return 0;
            } else if (c == QUIT_CHAR(tty)) {
                    n_tty_receive_signal_char(tty, SIGQUIT, c);
                    return 0;
            } else if (c == SUSP_CHAR(tty)) {
                    n_tty_receive_signal_char(tty, SIGTSTP, c);
                    return 0;
            }
    }

I'll update this answer if I get over my fears and actually try it...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ninjalj
Solution 2 jcomeau_ictx