Normally when we use fork the child will inherit the workspace of the parent.And also the child and the parent will run simultaneously.and any one can finish its process first.
Now come to your doubt,
Your while loop runs twice.Beginning of the loop you print some thing like " before fork():getpid()= 6010 " .When the first iteration a child process will get create.So the child and parent start to run simultaneously.So the statements can print in any order.
So the child have a provision the iterate the loop.So it will print the "before fork statement" .When the next iteration of the loop also the "bofore fork will get print.And the child process will get create and the appropriate statements will get print.
When the try for the next iteration the condition will get false.So it will come out.
Here :
One of the "before fork" statement is printed by the child process.
is there any technique to print the statements in the right order.
by right order i mean : to print the statements that come under same process rather than printing randomly.
i am unable to understand the process concept it self.