Skip to content

Instantly share code, notes, and snippets.

@lesovsky
Created July 30, 2015 10:54
Show Gist options
  • Save lesovsky/8d0563302217c43bb9d0 to your computer and use it in GitHub Desktop.
Save lesovsky/8d0563302217c43bb9d0 to your computer and use it in GitHub Desktop.
Simple SIGINT handling.
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
void sig_handler(int signo)
{
if (signo == SIGINT) {
printf("received SIGINT\n");
exit(0);
}
}
int main(void)
{
if (signal(SIGINT, sig_handler) == SIG_ERR)
printf("\ncan't catch SIGINT\n");
while(1)
sleep(1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment