Created
December 6, 2012 22:16
-
-
Save moretea/4228993 to your computer and use it in GitHub Desktop.
Tip: Use a signal handler to be able to run valgrind on a server program
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 <stdio.h> | |
| #include <unistd.h> | |
| #include <signal.h> | |
| static char keep_running; | |
| void handler(int signal) { | |
| printf("Got signal %i, closing down soon!\n", signal); | |
| keep_running = 0; | |
| } | |
| int main(int argc, char *argv[]) { | |
| /* Setup signal handler */ | |
| signal(SIGINT, handler); | |
| signal(SIGQUIT, handler); | |
| keep_running = 1; | |
| while(keep_running == 1) { | |
| printf("ZZZZZ\n"); | |
| sleep(1); | |
| printf("zzzzz\n"); | |
| sleep(1); | |
| } | |
| printf("Cleaning up\n"); | |
| /* close files / release memory */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment