Can anyone help me to understand what are the differences between the following three ways of handling a signal? I'm operating in a client/server in C.
Edit: I've understood that the 1st example is wrong, now I'd like to know which is better/possible, the 2nd one ore the third one? I've also read around the web that someone does a mix between them, using the "struct sigaction sig" in "sigemptyset" and "sigaddset", without any sigprocmask. Is this better than both my solutions?
Handler:
void closeSig(){
close(socketAccept);
close(socket);
exit(1);
}
1st example:
signal(SIGINT, closeSig);
2nd example:
sigset_t set;
struct sigaction sig;
sigemptyset(&set);
sigaddset(&set, SIGINT);
sig.sa_sigaction = &closeSig;
sig.sa_flags = SA_SIGINFO;
sig.sa_mask = set;
sigaction(SIGINT, &sig, NULL);
sigprocmask(SIG_UNBLOCK, &set, NULL);
3rd example:
struct sigaction sig;
sig.sa_sigaction = &closeSig;
sig.sa_flags = SA_SIGINFO;
sigaction(SIGINT, &sig, NULL);
sigaction()andsignal()? What information was missing for you? Why didn't you mention that you'd looked at it? - Jonathan Lefflersigprocmask()in the question, but mentionsigset()and its relatives (sigrelse(),sighold(),sigpause(),sigignore()) in your comment. There's alsopthread_sigmask(). Thesigset()family should not be used, in general — they are marked 'obsolescent' and new code should not use them. What are you really interested in? - Jonathan Lefflerexit()from a signal handler is not good idea. - alk