I try to draw out the process according to the code but I really need some explanation in why, here is the question:
B() {
pid_t pid;
if ((pid = fork()) != 0)
waitpid(pid,NULL,0);
printf("2");
if(fork() ==0)
{ printf("3"); exit(0); }
printf("5");
exit(0);
}
Which one are illegals output?
232553, 235325, 232355, 235253, 252533...
This is the process I draw out according to the code and my understanding of fork.
___3 (exit so no more here)
|
__2__|___5 (I guess 5 should be here)
| |
| |
____|____(wait)|(start again since printf 3 process end)
So I'm stuck right there... Any help is appreciated.