Guest User

Untitled

a guest
Dec 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include “csapp.h”
  2. int count = 0;
  3. void handler_usr1(int sig) { count += 1; }
  4. void handler_usr2(int sig) { count -= 1; }
  5. int main(void) {
  6. pid_t pid;
  7. int status;
  8. Signal(SIGUSR1, handler_usr1);
  9. Signal(SIGUSR2, handler_usr2);
  10.  
  11. if ((pid = Fork()) == 0) {
  12. printf("1");
  13. Kill(getppid(), SIGUSR1);
  14. } else {
  15. printf("2");
  16. Kill(pid, SIGUSR2);
  17. }
  18. if (pid == 0){
  19. if ((pid = Fork()) == 0){
  20. printf("3");
  21. Kill(getppid(), SIGUSR1);
  22. } else {
  23. printf("4");
  24. Kill(pid, SIGUSR2);
  25. }
  26. }
  27. if (pid > 0) {
  28. while(Waitpid(-1,&status,0) > 0) {
  29. if (!WIFEXITED(status))
  30. printf("child terminated abnormally!n");
  31. }
  32. }
  33. printf(“n”);
  34. // printf("Count: %d n", count);
  35. }
Add Comment
Please, Sign In to add comment