bash 如何在bash中将密钥绑定到sigkill?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/339887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:34:27  来源:igfitidea点击:

How to bind a key to sigkill in bash?

linuxbashsigkill

提问by Daniel Lucraft

I'm developing my application (on Linux) and sadly it sometimes hangs. I can use Ctrl+Cto send sigint, but my program is ignoring sigint because it's too far gone. So I have to do the process-killing-dance:

我正在开发我的应用程序(在 Linux 上),遗憾的是它有时会挂起。我可以Ctrl+C用来发送 sigint,但我的程序忽略了 sigint,因为它太远了。所以我必须做过程杀戮之舞:

Ctrl+Z
$ ps aux | grep process_name
$ kill -9 pid

Is there a way to configure bash to send the kill signal to the current process when I press - say - Ctrl+Shift+C?

有没有办法配置 bash 以在我按下 - 说 - 时将终止信号发送到当前进程Ctrl+Shift+C

回答by camh

I don't think there is any key you can use to send a SIGKILL.

我认为没有任何密钥可用于发送 SIGKILL。

Will SIGQUIT do instead? If you are not catching that, the default is to core dump the process. By default this is ^\. You can see this by running:

SIGQUIT 会代替吗?如果你没有发现,默认是核心转储进程。默认情况下,这是 ^\。您可以通过运行看到这一点:

$ stty -a

in a terminal. It should say:

在一个终端。它应该说:

quit = ^\

回答by Hasturkun

You can send a SIGQUIT signal to the current foreground process by pressing ^\ (by default, you can run stty -ato see the current value for quit.)

您可以通过按 ^\ 向当前前台进程发送 SIGQUIT 信号(默认情况下,您可以运行stty -a以查看 的当前值quit。)

You can also kill the last backgrounded process from the shell by running

您还可以通过运行从 shell 杀死最后一个后台进程

$ kill %%

回答by Vinko Vrsalovic

Given that there's no bound key for SIGKILL, what you can do is to create an alias to save some typing, if SIGQUIT doesn't cut it for you. First, the

鉴于 SIGKILL 没有绑定键,如果 SIGQUIT 没有为您剪切它,您可以做的是创建一个别名来保存一些输入。首先,

Ctrl+Z
$ ps aux | grep process_name
$ kill -9 pid

dance can be summarized (if there's only one instance of the process that you want to kill) as

舞蹈可以概括为(如果只有一个你想杀死的进程实例

Ctrl+Z
$ pkill -9 process_name

if your use case always goes to suspend then kill, you can create an alias to kill the last process ran like

如果你的用例总是挂起然后杀死,你可以创建一个别名来杀死最后一个运行的进程

$alias pks="pkill -9 !!:0"

Add that alias in your ~/.bash_profile.

在您的 ~/.bash_profile 中添加该别名。