如何在 bash 中将密钥绑定到 sigkill ?
我正在开发我的应用程序(在 Linux 上),遗憾的是它有时会挂起。 我可以使用 Ctrl+C 发送 sigint,但我的程序忽略 sigint,因为它太远了。 所以我必须执行进程终止舞蹈:
Ctrl+Z
$ ps aux | grep process_name
$ kill -9 pid
有没有办法配置 bash,当我按下 - 比如说 - Ctrl+Shift+C
时,将终止信号发送到当前进程?
I'm developing my application (on Linux) and sadly it sometimes hangs. I can use Ctrl+C
to send sigint, but my program is ignoring sigint because it's too far gone. So I have to do the process-killing-dance:
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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为没有任何密钥可以用来发送 SIGKILL。
SIGQUIT 会代替吗? 如果您没有注意到这一点,则默认情况是核心转储进程。 默认情况下这是 ^\。 您可以通过
在终端中运行:来查看这一点。 应该说:
I don't think there is any key you can use to send a 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:
in a terminal. It should say:
您可以通过按^\向当前前台进程发送SIGQUIT信号(默认情况下,您可以运行
stty -a
来查看quit
的当前值。)您可以还可以通过运行来终止 shell 中最后一个后台进程
You can send a SIGQUIT signal to the current foreground process by pressing ^\ (by default, you can run
stty -a
to see the current value forquit
.)You can also kill the last backgrounded process from the shell by running
鉴于 SIGKILL 没有绑定键,如果 SIGQUIT 不能为您减少输入,您可以做的是创建一个别名来节省一些输入。 首先,
可以总结这种舞蹈(如果您想终止的进程只有一个实例),就好像
您的用例总是先挂起然后终止,您可以创建一个别名来终止最后一个实例流程就像
在 ~/.bash_profile 中添加该别名一样运行。
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
dance can be summarized (if there's only one instance of the process that you want to kill) as
if your use case always goes to suspend then kill, you can create an alias to kill the last process ran like
Add that alias in your ~/.bash_profile.