Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <inttypes.h>
  5.  
  6. int f = 0;
  7.  
  8. void
  9. handler1(int sig)
  10. {
  11. f = 0;
  12. }
  13.  
  14. void
  15. handler2(int sig)
  16. {
  17. f = 1;
  18. }
  19.  
  20. int
  21. main(void)
  22. {
  23. struct sigaction sa1, sa2;
  24. sigemptyset(&sa1.sa_mask);
  25. sigemptyset(&sa2.sa_mask);
  26. sa1.sa_flags = SA_RESTART;
  27. sa2.sa_flags = SA_RESTART;
  28. sa1.sa_handler = handler1;
  29. sa2.sa_handler = handler2;
  30. sigaction(SIGINT, &sa1, NULL);
  31. sigaction(SIGQUIT, &sa2, NULL);
  32. printf("%d\n", getpid());
  33. fflush(stdout);
  34. uint32_t a, s = 0;
  35. while (scanf("%" PRId32, &a) == 1) {
  36. if (!f) {
  37. s += a;
  38. } else {
  39. s *= a;
  40. }
  41. printf("%" PRId32 "\n", s);
  42. fflush(stdout);
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement