c - 使用 SIGINT 后恢复 CTRL+C 的默认行为

标签 c linux signals

<分区>

我需要编写一个函数,在按下 CTRL+\后恢复 CTRL+C(终止进程)的默认行为 这是我的程序:

#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

void sig_int(int sig)
{

    printf("U PRESSED CTRL+C\n");
}
void sig_quit(int sig){
            printf("CTRL+C NOW DO ITS KILLING JOB\n");

}
int main(int argc, char** argv) 
{
    signal(SIGINT,sig_int);
    signal(SIGQUIT, sig_quit);

    return 0;
}

感谢您提供的所有帮助和描述,以便更好地理解 :)

最佳答案

摘 self 机器上的手册页:

To set the default action of the signal to occur as listed above, func should be SIG_DFL.

所以 signal(SIQUIT, SIG_DFL) 如果我正确理解了你的问题。

关于c - 使用 SIGINT 后恢复 CTRL+C 的默认行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50768335/

相关文章:

c - 移植 OS-9 信号处理程序

c - 多维数组中的字符串初始化

c - 32 位兼容模式下的 sizeof(int*)

c++ - 我如何找出哪个 header /包含在源中声明了哪些变量?

linux - 汇编中的 ROT13 密码

linux - linux在哪里开启虚拟内存?

c - 为 Windows x64 构建 openSSL

c++ - "const"只是意味着只读还是更多?

python - Django:断开 post_save 信号以避免递归

c - 信号处理程序不处理信号