Advertisement
Tobiahao

S01_LAB01_05

Nov 12th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. /*
  2. Napisz dwa programy. Program pierwszy stworzy dwa procesy, a następnie
  3. program procesu potomnego zastąpi programem drugim.
  4. */
  5.  
  6. // Program 1
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10.  
  11. int main(void)
  12. {
  13.     pid_t pid;
  14.  
  15.     pid = fork();
  16.     if(pid == 0){
  17.         if(execl("./05_2", "05_2", (char *)NULL) == -1){
  18.             perror("execl");
  19.             return EXIT_FAILURE;
  20.         }
  21.         return EXIT_SUCCESS;   
  22.     }
  23.     else if(pid == -1){
  24.         perror("fork");
  25.         return EXIT_FAILURE;
  26.     }
  27.  
  28.     return EXIT_SUCCESS;
  29. }
  30.  
  31. // Program 2
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34.  
  35. int main(void)
  36. {
  37.     printf("Program drugi!\n");
  38.  
  39.     return EXIT_SUCCESS;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement