Last active
December 14, 2015 03:48
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: 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