^尽管有 stty 声明,但你不会杀人

^U does not kill despite stty claims

问题: ctrl+U 不会杀死我的终端程序。


详情: 这是我在 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

如您所见,它描述了可用的信号中断:
^C = intr
^ \ = 退出
^U = kill
等...

这是一个无限 运行ning 程序:

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

ctrl+C 有效

$./main                                                             
^C
$

ctrl+\ 有效

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

ctrl+U 工作。
为什么我不能用这种方式杀死终端程序?

我当然可以找到进程ID和运行 kill -9 <PID>,
但我希望 shorthand 起作用。


我在 Ubuntu:

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

这是我的终端规格,但我试过其他终端(可能不相关)

gnome-terminal --version                                           
GNOME Terminal 3.6.2

它在 xterm 上也不起作用。我也尝试过不同的外壳:
shbashzsh

可能是什么问题?我现在应该去哪里看?

stty输出中的

kill指的是kill-line字符,即按^U擦除到行首。

发送中断信号的字符是intrquitsusp,在某些系统上(不是Linux IIRC),dsusp.

要实现这样的事情,您必须添加另一个信号,比如 VPKILLPKILL_CHAR 用于 process kill,而不是现有的 VKILLKILL_CHARinclude/linux/tty.h 中; Linux 源中 drivers/tty/n_tty.c 的新 else if 子句,并相应地修改任何其他必要的头文件和驱动程序文件。我怀疑这说起来容易做起来难,因为这个逻辑在非常低的水平上融入了 Linux,并且内核的其他部分很可能存在会导致稳定性丧失和 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;
            }
    }

如果我克服了恐惧并实际尝试了,我会更新这个答案...