i ran the following code and got strange results....
Code:
int main(int argc, char *argv[] )
{
int i =0;
for(i=0;i<2;i++)
{
printf("%d child proc b4 %d\n",i, (int) getpid());
printf(" parent proc %d\n", (int) getppid());
fork();
printf("%d child proc af %d\n\n",i, (int) getpid());
}
return EXIT_SUCCESS;
}
the results i got
0 child proc b4 16544 <-------------
parent proc 16027
0 child proc af 16544
1 child proc b4 16544
parent proc 16027
1 child proc af 16544 <-------------- does this indicate that the fork(); call takes longer
------------------------------------------------- than the loop to output to stdout ??
0 child proc af 16545
1 child proc b4 16545
parent proc 16544 <---------------- does this mean that the parent of this fork is the child
------------------------------------------------ of the first parent
1 child proc af 16546
1 child proc af 16545 <--------------- ?????? and is this that the process somehow calls
------------------------------------------------ the print statement again ??? or stdout ???
1 child proc af 16547
really confused, would appreciate any insight ....
thanks