Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <errno.h>
  6. #include <sys/wait.h>
  7. #include <sys/types.h>
  8. #define N 2
  9. void macierzysty()
  10. {
  11.  
  12. int i;
  13. for(i=1;i<=N;i++)
  14. {
  15. printf("+++Proces macierzysty i=%d\n", i);
  16. }
  17. printf("+++Proces macierzysty zakonczony\n");
  18. //if(wait(0) == -1){printf("def Error in fork = %d %s", errno, strerror(errno));}
  19. }
  20.  
  21. void potomny()
  22. {
  23. int j;
  24. for(j=1;j<=N;j++)
  25. {
  26. printf("---Proces potomny j=%d\n", j);
  27. }
  28. printf("---Proces potomny zakonczony\n");
  29.  
  30. }
  31. int main()
  32. {
  33. int liczba;
  34. switch(liczba = fork())
  35. {
  36. case -1: printf("Error in fork = %d %s\n", errno, strerror(errno));
  37. case 0: potomny();
  38. return 0;
  39. default :
  40.  
  41. macierzysty();
  42. waitpid(0);
  43. if(wait(0) == -1){printf("def Error in fork = %d %s", errno, strerror(errno));}
  44. return 0;
  45. }
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement