Advertisement
Tobiahao

S01_LAB01_03

Nov 12th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. /*
  2. Napisz program, który stworzy dwa procesy. Proces macierzysty powinien poczekać
  3. na wykonanie procesu potomnego i zbadać status jego wyjścia.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9. #include <sys/types.h>
  10. #include <sys/wait.h>
  11.  
  12. int main(void)
  13. {
  14.     int wstatus;
  15.  
  16.     pid_t pid = fork();
  17.     if(pid == 0){
  18.         // Potomek
  19.     }
  20.     else if(pid > 0){
  21.         // Rodzic
  22.         wait(&wstatus);
  23.         printf("Potomek zakonczyl dzialanie ze statusem wyjscia: %d\n", wstatus);
  24.     }
  25.     else{
  26.         perror("fork");
  27.         return EXIT_FAILURE;
  28.     }
  29.  
  30.     return EXIT_SUCCESS;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement