[英]Catch all signals that would stop a program
I've got a program to catch any terminating signals. 我有一个程序可以捕获任何终止信号。 Currently all it does is catch Ctrl + C .
当前所做的只是捕获Ctrl + C。 I want to be able to catch Ctrl + Z and Ctrl + \\ in addition to Ctrl + C .
除了Ctrl + C之外,我还希望能够捕获Ctrl + Z和Ctrl + \\ 。 Here's part of my code.
这是我的代码的一部分。
if (signal(SIGINT, SIG_IGN) == SIG_ERR)
fprintf(stderr,"Error: Can't catch SIGINT\n");
if (signal(SIGTERM, SIG_IGN) == SIG_ERR)
fprintf(stderr,"Error: Can't catch SIGTERM\n");
// do stuff
What other signals to I need to implement to catch Ctrl + Z and Ctrl + \\ ? 我还需要实现什么其他信号来捕获Ctrl + Z和Ctrl + \\ ? And what raises
SIGTERM
? 什么引起了
SIGTERM
? Thanks in advance. 提前致谢。
Ctrl+Z raises SIGTSTP. Ctrl + Z引发SIGTSTP。 Ctrl+\\ raises SIGQUIT.
Ctrl + \\引发SIGQUIT。
I don't know of any key combination that raises SIGTERM, but of course you can send it using kill -TERM <pid>
replacing <pid>
with the process ID. 我不知道会引起SIGTERM的任何键组合,但是您当然可以使用
kill -TERM <pid>
将<pid>
替换为进程ID来发送它。 (Or just kill <pid>
; SIGTERM is the default signal for kill
) (或者只是
kill <pid>
; SIGTERM是kill
的默认信号)
Note that you can't catch SIGSTOP nor SIGKILL. 请注意,您无法捕获SIGSTOP或SIGKILL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.