Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- volatile int count2 = 0;
- volatile int count1 = 0;
- volatile int breaks = 0;
- void usr2(int sig) {
- ++count2;
- }
- void usr1(int sig) {
- printf("%d\n", count1);
- fflush(stdout);
- printf("%d\n", count2);
- fflush(stdout);
- ++count1;
- }
- void process(int sig) {
- breaks = 1;
- }
- int main() {
- signal(SIGUSR2, usr2);
- signal(SIGUSR1, usr1);
- signal(SIGTERM, process);
- if (breaks) return 0;
- sigset_t s2, s1;
- sigemptyset(&s1);
- sigaddset(&s1, SIGINT);
- sigprocmask(SIG_BLOCK, &s1, &s2);
- while (1) {
- sigsuspend(&s2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement