Advertisement
Sevashi

Untitled

Dec 8th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5.  
  6.  
  7.  
  8. int main(){
  9.  
  10. pid_t pot[10];
  11.  
  12. //Proces macierzysty P1
  13. switch (pot[1]=fork()){
  14. case 0:
  15. //Proces potomny P2
  16. switch(pot[2]=fork()){
  17.  
  18. case 0:
  19. //Proces potomny P4
  20. switch(pot[4]=fork()){
  21.  
  22. case 0:
  23. printf("P4:%d:%d\n", getpid(),getppid());
  24. exit(0);
  25.  
  26. case -1:
  27. printf("Blad\n");
  28. exit(1);
  29.  
  30. default:
  31. wait(NULL);
  32.  
  33. }
  34. //Proces potomny P5
  35. switch(pot[5]=fork()) {
  36.  
  37. case 0:
  38. //Proces potomny P8
  39. switch (pot[8] = fork()) {
  40.  
  41. case 0:
  42. printf("P8:%d:%d\n", getpid(), getppid());
  43. exit(0);
  44.  
  45. case -1:
  46. printf("Blad\n");
  47. exit(1);
  48.  
  49. default:
  50. wait(NULL);
  51. }
  52. //Proces potomny P9
  53. switch (pot[9] = fork()) {
  54. case 0:
  55. printf("P9:%d:%d\n", getpid(), getppid());
  56. exit(0);
  57.  
  58. case -1:
  59. printf("Blad\n");
  60. exit(1);
  61.  
  62. default:
  63. wait(NULL);
  64.  
  65. }
  66. //Dalsza czesc procesu P5
  67. case -1:
  68. printf("Blad\n");
  69. exit(1);
  70. default:
  71. printf("P1:%d:%d:%d\n", getpid(), getppid(), pot[8], pot[9]);
  72. wait(NULL);
  73.  
  74. }
  75. //Dalsza czesc procesu P2
  76. case -1:
  77. printf("Blad\n");
  78. exit(1);
  79. default:
  80. printf("P1:%d:%d:%d\n", getpid(), getppid(), pot[4], pot[5]);
  81. wait(NULL);
  82.  
  83. }
  84. //Proces potomny P3
  85. switch(pot[3]=fork()){
  86. case 0:
  87. //Proces potomny P6
  88. switch(pot[6]=fork()){
  89. case 0:
  90. printf("P6:%d:%d\n", getpid(),getppid());
  91. exit(0);
  92.  
  93. case -1:
  94. printf("Blad\n");
  95. exit(1);
  96.  
  97. default:
  98. wait(NULL);
  99. }
  100. //Proces potomny P7
  101. switch(pot[7]=fork()){
  102. case 0:
  103. //Proces potomny P10
  104. switch(pot[10]=fork()){
  105. case 0:
  106. printf("P10:%d:%d\n", getpid(),getppid());
  107. exit(0);
  108.  
  109. case -1:
  110. printf("Blad\n");
  111. exit(1);
  112.  
  113. default:
  114. wait(NULL);
  115. }
  116. //Dalsza czesc procesu P7
  117. case -1:
  118. printf("Blad\n");
  119. exit(1);
  120.  
  121. default:
  122. printf("P1:%d:%d:%d\n", getpid(), getppid(), pot[10]);
  123. wait(NULL);
  124. }
  125. //Dalsza czesc procesu P3
  126. case -1:
  127. printf("Blad\n");
  128. exit(1);
  129.  
  130. default:
  131. printf("P1:%d:%d:%d:%d\n", getpid(), getppid(), pot[6], pot[7]);
  132. wait(NULL);
  133.  
  134. }
  135. //Dalsza czesc procesu P1
  136. case -1:
  137. printf("Blad\n");
  138. exit(1);
  139.  
  140. default:
  141. printf("P1:%d:%d:%d:%d\n", getpid(), getppid(), pot[2], pot[3]);
  142. wait(NULL);
  143.  
  144. }
  145.  
  146.  
  147. return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement