Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <signal.h>
- #include <unistd.h>
- int cnt = 0;
- void sigint_handler(int signo)
- {
- if (cnt < 4) {
- printf("%d\n", cnt);
- fflush(stdout);
- ++cnt;
- } else {
- _exit(0);
- }
- }
- int main()
- {
- sigset_t mask, oldmask;
- sigemptyset(&mask);
- sigaddset(&mask, SIGINT);
- sigprocmask(SIG_BLOCK, &mask, &oldmask);
- struct sigaction sa;
- sa.sa_handler = sigint_handler;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESTART;
- sigaction(SIGINT, &sa, NULL);
- printf("%d\n", getpid());
- fflush(stdout);
- sigprocmask(SIG_UNBLOCK, &mask, &oldmask);
- while (1) {
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement