Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <sys/wait.h>
  5.  
  6. volatile int count2 = 0;
  7. volatile int count1 = 0;
  8. volatile int breaks = 0;
  9.  
  10. void usr2(int sig) {
  11. ++count2;
  12. }
  13.  
  14. void usr1(int sig) {
  15. printf("%d\n", count1);
  16. fflush(stdout);
  17. printf("%d\n", count2);
  18. fflush(stdout);
  19. ++count1;
  20. }
  21.  
  22. void process(int sig) {
  23. breaks = 1;
  24. }
  25.  
  26. int main() {
  27. signal(SIGUSR2, usr2);
  28. signal(SIGUSR1, usr1);
  29. signal(SIGTERM, process);
  30. if (breaks) return 0;
  31.  
  32. sigset_t s2, s1;
  33. sigemptyset(&s1);
  34. sigaddset(&s1, SIGINT);
  35. sigprocmask(SIG_BLOCK, &s1, &s2);
  36.  
  37. while (1) {
  38. sigsuspend(&s2);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement