I use:
signal(SIGINT, CtrlHandler);
To add handler of SIGINT event. But how can i delete this handler?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is what you do:
That resets the signal handler back to whatever the default behavior was for that signal (including the default disposition if it hasn’t been set). In the case of SIGINT, it’s aborting your process without a core dump.
The manual for
signalexplains why this works:You can also find this information using the
mancommand. If you typeman signalon the command line and read through, you should see it.This is very specific to the case in which you’ve replaced the system default signal handler. In some situations, what you want is to simply restore whatever handler was there in the first place. If you look at the definition of
signalit looks like this:So, it returns a
sighandler_t. Thesighandler_tthat it returns represents the previous ‘disposition’ of the signal. So, another way to handle this is to simply save the value it returns and then restore that value when you want to remove your own handler.