Skip to content

Instantly share code, notes, and snippets.

@cstorey
Last active December 14, 2015 03:48
Show Gist options
  • Save cstorey/5023376 to your computer and use it in GitHub Desktop.
Save cstorey/5023376 to your computer and use it in GitHub Desktop.
Test program for re-enterancy of signal handlers. Compile with 'gcc -o signal signal.c' (or adjust to taste).
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void
handler(int signum)
{
printf("Catching signal %d\n",signum);
sleep(1);
printf("Done handling %d\n", signum);
}
int main()
{
// Register signal and signal handler
signal(SIGINT, handler);
signal(SIGQUIT, handler);
while(1)
{
printf("Doing meaningful work\n")
pause();
}
return EXIT_SUCCESS;
}
: cez@rhk; ./a.out
Program processing stuff here.
^CCaught signal 2
Exit signal handler for 2
Program processing stuff here.
^\Caught signal 3
Exit signal handler for 3
Program processing stuff here.
^CCaught signal 2
^\Caught signal 3
Exit signal handler for 3
Exit signal handler for 2
Program processing stuff here.
^\Caught signal 3
^CCaught signal 2
Exit signal handler for 2
Exit signal handler for 3
Program processing stuff here.
^Z
zsh: suspended ./a.out
: cez@rhk; kill %./a.out
: cez@rhk;
[1] + terminated ./a.out
: cez@rhk; fg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment