Skip to content

Instantly share code, notes, and snippets.

@paddya
Created November 23, 2012 12:29
Show Gist options
  • Save paddya/4135418 to your computer and use it in GitHub Desktop.
Save paddya/4135418 to your computer and use it in GitHub Desktop.
#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