Skip to content

Instantly share code, notes, and snippets.

@robbmanes
Created February 12, 2016 16:29
Show Gist options
  • Save robbmanes/4e19eaa84e29242c30fa to your computer and use it in GitHub Desktop.
Save robbmanes/4e19eaa84e29242c30fa to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#define IGNORE_ALL_SIGNALS 1
void signal_loop(int sig);
int main(int argc, char **argv)
{
#ifdef IGNORE_ALL_SIGNALS
sigset_t mask;
sigfillset(&mask);
sigprocmask(SIG_SETMASK, &mask, NULL);
#else
signal(SIGQUIT, signal_loop);
#endif
printf("Entering loop waiting for -3 signal...\n");
for(;;)
{
sleep(1);
}
return 0;
}
void signal_loop(int sig)
{
printf("Caught -3 SIQQUIT, press enter to continue.\n");
getchar();
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment