Is there a way to catch a signal just once with sigaction
structure and function? To be more specific, I would like to simply reset to default a specific signal (SIGINT
). Is it possible to achieve this in a handler?
Edit
So, something like this would be correct:
void sig_int(int sig) { printf(" -> Ctrl-C\n"); struct sigaction act; act.sa_handler = SIG_DFL; if(sigaction(SIGINT, &act, NULL) < 0) { exit(-1); } } int main() { struct sigaction act; act.sa_handler = sig_int; if(sigaction(SIGINT, &act, NULL) < 0) { exit(-1); } while(1) { sleep(1); } return 0; }