Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. #include<sys/types.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<unistd.h>
  5.  
  6. //          ______P1____
  7. //         /      |     \
  8. //     ___P2_     P3    P4  
  9. //    /   |  \   / \     |    
  10. //    P5  P6 P7 P8 P9   P10      
  11. //        |              |
  12. //       P11           (P12) <-- pstree
  13. int pid;
  14. int main(void)
  15. {
  16.  
  17. printf("Proces 1 PID:%d\n", getpid());
  18. if(pid=fork())//2
  19. {
  20.     printf("Proces 2 PID:%d\n", pid);
  21. }
  22. else
  23. {
  24.     if(pid=fork())//5
  25.     {
  26.         printf("Proces 5 PID:%d\n", pid);
  27.     }
  28.     else
  29.     {
  30.         sleep(1);
  31.         exit(0);
  32.     }
  33.     if(pid=fork())//6
  34.     {
  35.         printf("Proces 6 PID:%d\n", pid);
  36.     }
  37.     else
  38.     {
  39.         if(pid=fork())//11
  40.         {
  41.             printf("Proces 11 PID:%d\n", pid);
  42.         }
  43.         else
  44.         {
  45.             sleep(1);
  46.             exit(0);
  47.         }
  48.         sleep(1);
  49.         exit(0);
  50.     }
  51.     if(pid=fork())//7
  52.     {
  53.         printf("Proces 7 PID:%d\n", pid);
  54.     }
  55.     else
  56.     {
  57.         sleep(1);
  58.         exit(0);
  59.     }
  60.     sleep(1);
  61.     exit(0);
  62. }
  63.  
  64. if(pid=fork())//3
  65. {
  66.     printf("Proces 3 PID:%d\n", pid);
  67. }
  68. else
  69. {
  70.     if(pid=fork())//8
  71.     {
  72.         printf("Proces 8 PID:%d\n", pid);
  73.         if(pid=fork())//9
  74.         {
  75.             printf("Proces 9 PID:%d\n",pid);
  76.         }
  77.         else
  78.         {
  79.             sleep(1);
  80.             exit(0);
  81.         }
  82.     }
  83.     else
  84.     {
  85.         sleep(1);
  86.         exit(0);
  87.     }
  88.     sleep(1);
  89.     exit(0);
  90. }
  91.  
  92. if(pid=fork())//4
  93. {
  94.     printf("Proces 4 PID:%d\n", pid);
  95. }
  96. else
  97. {
  98.     if(pid=fork())//10
  99.     {
  100.         printf("Proces 10 PID:%d\n", pid);
  101.     }
  102.     else
  103.     {
  104.         if(pid=fork())
  105.         {
  106.             printf("Proces 12 PID:%d\n", pid);
  107.         }
  108.         else
  109.         {
  110.             //system("pstree -c");
  111.             execlp("pstree","pstree","-c",(char*)NULL);
  112.             sleep(1);
  113.             exit(0);
  114.         }
  115.         sleep(1);
  116.         exit(0);
  117.     }
  118.     sleep(1);
  119.     exit(0);
  120. }
  121. getchar();
  122. return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement