Advertisement
Tobiahao

S01_LAB01_12

Nov 12th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. /*
  2. Aby procesy potomne nie stawały się procesami zombie wystarczy, żeby proces
  3. macierzysty ignorował sygnał SIGCHLD. Napisz program, który sprawdzi, czy
  4. rzeczywiście tak się dzieje i co w takim przypadku zwraca wait() lub waitpid() po
  5. zakończeniu potomka.
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <signal.h>
  12. #include <wait.h>
  13.  
  14. int main(void)
  15. {
  16.     pid_t pid;
  17.  
  18.     pid = fork();
  19.     if(pid == -1){
  20.         perror("fork");
  21.         return EXIT_FAILURE;
  22.     }
  23.     else if(pid == 0){
  24.         printf("Koniec potmoka\n");
  25.     }
  26.     else{
  27.         if(signal(SIGCHLD, SIG_IGN) == SIG_ERR){
  28.             perror("signal");
  29.             return EXIT_FAILURE;
  30.         }
  31.         printf("Po zakonczeniu potomka funkcja wait zwraca: %d - czyli blad\n", wait(NULL));
  32.     }
  33.  
  34.     return EXIT_SUCCESS;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement