Created
November 23, 2012 12:29
-
-
Save paddya/4135418 to your computer and use it in GitHub Desktop.
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 <stdlib.h> | |
#include <time.h> | |
static time_t lastSignal = 0; | |
void handler(int sig) { | |
if(sig != SIGINT) { | |
return; | |
} else { | |
printf("Received signal.\n"); | |
time_t now; | |
time(&now); | |
if(lastSignal > 0 && (now - lastSignal) <= 2) { | |
exit(EXIT_SUCCESS); | |
} | |
lastSignal = now; | |
} | |
} | |
int main( void ) | |
{ | |
/* Place your handler somewhere around here */ | |
printf( "Hello World!\n" ); | |
for ( ;; ) | |
{ | |
/* infinite loop */ | |
signal(SIGINT, handler); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment