Skip to content

Instantly share code, notes, and snippets.

@tedz2usa
Last active May 16, 2017 18:34
Show Gist options
  • Save tedz2usa/e8501c9297ad319cf21623aed1af0c69 to your computer and use it in GitHub Desktop.
Save tedz2usa/e8501c9297ad319cf21623aed1af0c69 to your computer and use it in GitHub Desktop.
http://stackoverflow.com/questions/1641182/how-can-i-catch-a-ctrl-c-event-c
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
void my_handler(int s){
printf("Caught signal %d\n",s);
exit(1);
}
int main(int argc,char** argv)
{
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = my_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
pause();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment