取消绑定sigaction处理程序

时间:2011-12-06 19:41:59

标签: c gcc posix signals

我已成功将处理函数附加到SIG_INT和SIG_KILL,但现在我希望能够解除绑定"特定点处的处理程序(准确地称为fork之后)。这就是我附加处理程序的方式:

struct sigaction sa;
sa.sa_handler = interrupt_handler;
sigempty(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;

sigaction(SIG_INT, &sa, NULL);
sigaction(SIG_KILL, &sa, NULL);

interrupt_handler只打印一些东西。

1 个答案:

答案 0 :(得分:4)

您可能想要恢复之前的处置:

struct sigaction sa, oldsa;

/* Change it but save previous state. */
sigaction(SIG_INT, &sa, &oldsa);

/* ... */

/* Restore previous stuff. */
sigaction(SIG_INT, &oldsa, NULL);