Reputation: 5034
I've succesfully attached a handler function to SIG_INT and SIG_KILL but now I would like to be able to "unbind" the handler at a certain point (after a fork to be precise). This is how I attach the handler:
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 only prints something.
Upvotes: 0
Views: 219
Reputation: 182609
You probably want to restore the previous disposition:
struct sigaction sa, oldsa;
/* Change it but save previous state. */
sigaction(SIG_INT, &sa, &oldsa);
/* ... */
/* Restore previous stuff. */
sigaction(SIG_INT, &oldsa, NULL);
Upvotes: 4