Can any help me to write program using Fork in C to generate this tree structure?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shatha94
    New Member
    • Feb 2016
    • 1

    Can any help me to write program using Fork in C to generate this tree structure?

    the tree in the the attachment below

    this is my code that I'm tried to write :

    Code:
    #include<sys/types.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<unistd.h>
    
    int main()
    {
    
    printf("the parent id %d" , getpid());
    
    pid_t pid1,pid2,pid3;
    
    for (j=0;j<3;j++)
    {
    pid1=fork();
    printf("%d",getpid());
    }
    if (pid1==0)
    {
     pid2=fork();
    elseif (pid3=fork();
    }
     if((pid2 == 0)&&(pid3 == 0)) 
       {
           if (pid1 !=0)
           fork();
       }
    
    printf("the process id %d" , getpid());
    
    return 0;
    
    }
    Attached Files
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This is too big a subject for a thread like this.

    Start here:

    Comment

    Working...