【问题标题】:^U does not kill despite stty claims^尽管有 stty 声明,但你不会杀人
【发布时间】:2016-09-13 21:41:00
【问题描述】:

问题: 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 = 杀死
等等……

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

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

ctrl+C 有效

$./main                                                             
^C
$

ctrl+\有效

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

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

我当然可以找到进程 ID 并运行 kill -9 <PID>,
但我希望速记工作。


我在 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。我也尝试过不同的 shell:
shbash、ans zsh

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

【问题讨论】:

    标签: shell terminal signals ubuntu-14.04 stty


    【解决方案1】:

    stty 的输出中的kill 指的是kill-line 字符,即按^U 会擦除到行首。

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

    【讨论】:

    • 我明白了。那么除了使用kill之外,没有其他方法可以杀死吗?
    • 嗯,总是有 sysrq 键 (en.wikipedia.org/wiki/Magic_SysRq_key),但这会杀死当前虚拟终端上的每个进程,或者除 init 之外的所有进程。
    猜你喜欢
    • 1970-01-01
    • 2022-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多