I want to create a one level process tree using fork() system call, which looks as follows for n = 4 process
I have tried this with the following code but this is not working. (here 1 is a child of parent process )
for(i = 0 ;i < n; i++){
chid = fork();
if ( chid == 0 ){
printf("%d\n",getpid());
while(++i < n){
chid = fork();
if(chid == 0){
printf(" %d ",getpid());
break;
}
}
}
else
break;
}
How can I make this ?