Created
August 24, 2011 21:52
-
-
Save nfarring/1169363 to your computer and use it in GitHub Desktop.
Register a signal handler for SIGINT.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <signal.h> | |
/* | |
* Gracefully exits when Ctrl+C is pressed. | |
*/ | |
void sigint_handler(int signum) { | |
exit(0); | |
} | |
struct sigaction act; | |
memset((void *)&act, 0, sizeof(act)); | |
act.sa_handler = sigint_handler; | |
if (sigaction(SIGINT, &act, NULL) == -1) { | |
perror("sigaction"); | |
exit(-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment