I have the following code
int main ( int argc, char *argv[] ){
printf("This is parents pid %d", getpid());
for(int i=0;i<5;i++) // loop will run n times (n=5){
if(fork() == 0) {
printf("[son] pid %d from [parent] pid %d\n",getpid(),getppid());
exit(0);
}
}
for(int i=0;i<5;i++) // loop will run n times (n=5)
wait(NULL);
}
And for some reason the output is the following
Why it prints five times This is parent's pid??? Also when i just add a "\n" in the first print like that
printf("This is parents pid %d\n", getpid());
Can anyone please explain that to me???