Advertisement
Sevashi

Untitled

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