Last active
June 15, 2016 08:37
-
-
Save josephok/b59ce5344be6805d0c26c2bc3e77d0ee to your computer and use it in GitHub Desktop.
Write a program that shows that when the disposition of a pending signal is changed to be SIG_IGN , the program never sees (catches) the signal.
This file contains hidden or 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
// Write a program that shows that when the disposition of a pending signal is | |
// changed to be SIG_IGN , the program never sees (catches) the signal. | |
#include <signal.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
void printSigset(FILE *of, const char *prefix, const sigset_t *sigset) | |
{ | |
int sig, cnt; | |
cnt = 0; | |
for (sig = 1; sig < NSIG; sig++) { | |
if (sigismember(sigset, sig)) { | |
cnt++; | |
fprintf(of, "%s--%d\n", prefix, sig); | |
} | |
} | |
if (cnt == 0) | |
fprintf(of, "%s<empty signal set>\n", prefix); | |
} | |
static void handler(int sig) { | |
printf("Caught %d\n", sig); | |
} | |
static void handler2(int sig) { | |
printf("2Caught %d\n", sig); | |
} | |
int main(int argc, char const *argv[]) { | |
struct sigaction act; | |
act.sa_handler = handler; | |
sigaction(SIGINT, &act, NULL); | |
sigset_t blockingMask, emptyMask; | |
sigemptyset(&blockingMask); | |
sigaddset(&blockingMask, SIGINT); | |
sigprocmask(SIG_SETMASK, &blockingMask, NULL); | |
printSigset(stdout, "joseph", &blockingMask); | |
act.sa_handler = SIG_IGN; | |
sigaction(SIGINT, &act, NULL); | |
sigemptyset(&emptyMask); /* Unblock all signals */ | |
sigprocmask(SIG_SETMASK, &emptyMask, NULL); | |
while (1) { | |
pause(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment