Advertisement
Sevashi

Untitled

Dec 8th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 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 P2
  65. case -1:
  66. printf("Blad");
  67. exit(1);
  68.  
  69. default:
  70. printf("P1:%d:%d:%d", getpid(), getppid(), pid[4], pid[5])
  71. wait(NULL);
  72. }
  73.  
  74. }
  75. //Proces potomny P3
  76. switch(pid[3]=fork()){
  77. case 0:
  78. //Proces potomny P6
  79. switch(pid[6]=fork()){
  80. case 0:
  81. printf("P6:%d:%d", getpid(),getppid());
  82. exit(0)
  83.  
  84. case -1
  85. printf("Blad");
  86. exit(1);
  87.  
  88. default:
  89. wait(NULL);
  90. }
  91. //Proces potomny P7
  92. switch(pid[7]=fork()){
  93. case 0:
  94. //Proces potomny P10
  95. switch(pid[10]=fork()){
  96. case 0:
  97. printf("P10:%d:%d", getpid(),getppid());
  98. exit(0)
  99.  
  100. case -1
  101. printf("Blad");
  102. exit(1);
  103.  
  104. default:
  105. wait(NULL);
  106. }
  107. //Dalsza czesc procesu P7
  108. case -1
  109. printf("Blad");
  110. exit(1);
  111.  
  112. default:
  113. printf("P1:%d:%d:%d", getpid(), getppid(), pid[10])
  114. wait(NULL);
  115. }
  116. //Dalsza czesc procesu P3
  117. case -1
  118. printf("Blad");
  119. exit(1);
  120.  
  121. default:
  122. printf("P1:%d:%d:%d:%d", getpid(), getppid(), pid[6], pid[7])
  123. wait(NULL);
  124.  
  125. }
  126. //Dalsza czesc procesu P1
  127. case -1:
  128. printf("Blad");
  129. exit(1);
  130.  
  131. default:
  132. printf("P1:%d:%d:%d:%d", getpid(), getppid(), pid[2], pid[3])
  133. wait(NULL);
  134.  
  135. }
  136.  
  137.  
  138. return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement