Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<stdio.h>
  4. #include<unistd.h>
  5. #include<sys/types.h>
  6.  
  7. int main()
  8. {
  9.     char tree[80];
  10.     if(fork() == 0)
  11.     {
  12.         pid_t pid_1 = getpid();
  13.         printf("Proces pid_1 = %d\n", pid_1);
  14.         sprintf(tree, "pstree -cp %d", pid_1);
  15.         if(fork() == 0)
  16.         {
  17.             pid_t pid_2 = getpid();
  18.             printf("Proces pid_2 = %d\n", pid_2);
  19.             if(fork() == 0)
  20.             {
  21.                 pid_t pid_3 = getpid();
  22.                 printf("Proces pid_3 = %d\n", pid_3);
  23.                 sleep(100);
  24.                 _exit(0);
  25.             }
  26.             if(fork() == 0)
  27.             {
  28.                 pid_t pid_4 = getpid();
  29.                 printf("Proces pid_4 = %d\n", pid_4);
  30.                 sleep(100);
  31.                 _exit(0);
  32.             }
  33.             if(fork() == 0)
  34.             {
  35.                 pid_t pid_5 = getpid();
  36.                 printf("Proces pid_5 = %d\n", pid_5);
  37.                 sleep(100);
  38.                 _exit(0);
  39.             }
  40.             sleep(100);
  41.             _exit(0);
  42.         }
  43.  
  44.         if(fork() == 0)
  45.         {
  46.             pid_t pid_6 = getpid();
  47.             printf("Proces pid_6 = %d\n", pid_6);
  48.             if(fork() == 0)
  49.             {
  50.                 pid_t pid_6 = getpid();
  51.                 printf("Proces pid_6 = %d\n", pid_6);
  52.                 sleep(100);
  53.                 _exit(0);
  54.             }
  55.             if(fork() == 0)
  56.             {
  57.                 pid_t pid_7 = getpid();
  58.                 printf("Proces pid_7 = %d\n", pid_7);
  59.                 sleep(100);
  60.                 _exit(0);
  61.             }
  62.             if(fork() == 0)
  63.             {
  64.                 pid_t pid_8 = getpid();
  65.                 printf("Proces pid_8 = %d\n", pid_8);
  66.                 sleep(100);
  67.                 _exit(0);
  68.             }
  69.             sleep(100);
  70.             _exit(0);
  71.         }
  72.         system(tree);
  73.         sleep(100);
  74.         _exit(0);
  75.     }
  76.  
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement