I'm just starting to fork()
and I'm having some difficulties understanding the parallel execution. I've found this example code and I want to know if the first time it will go true
or false
(I know if pid1==0
it means it's a child, etc). I also want to know how many copies (children will be created) and some details on the general execution.
I have tried to run it and added the return 0;
(my original source didn't have it) just to see if exits... but as you can see it "waits"
https://i.stack.imgur.com/VULJZ.png
int main(void)
{
int pid1, pid2, pid3, pid4;
pid1=fork();
if (pid1!=0)
{
pid2=fork();
pid3=fork();
printf("\t\t IF(TRUE) pid1=%d and pid2=%d and pid3=%d\n",
pid1, pid2, pid3);
}
else
{
pid4=fork();
printf("\nIF(False) FATHER is talking with pid1=%d and pid4=%d\n",
pid1, pid4);
}
return 0;
}