Guest User

Untitled

a guest
Dec 9th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <signal.h>
  5. #include <string.h>
  6. #include <sys/types.h>
  7. #include <sys/wait.h>
  8.  
  9. sig_atomic_t child_exit_status;
  10.  
  11. void clean_up_child_process(int signal_number)
  12. {
  13. int status;
  14. wait(&status);
  15. child_exit_status = status;
  16. }
  17.  
  18. int main()
  19. {
  20. struct sigaction sigchld_action;
  21. memset(&sigchld_action, 0, sizeof(sigchld_action));
  22. sigchld_action.sa_handler = &clean_up_child_process;
  23. sigaction(SIGCHLD, &sigchld_action, NULL);
  24.  
  25. pid_t child_pid = fork();
  26. if (child_pid > 0) {
  27. printf("Parent process, normal executionn");
  28. sleep(60);
  29. printf("After sleepn");
  30. } else {
  31. printf("Childn");
  32. }
  33.  
  34. return 0;
  35. }
  36.  
  37. Parent process, normal execution
  38. Child
  39. After sleep
Add Comment
Please, Sign In to add comment