The following code:
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);
}
could have one of the outputs: and im not sure which one is the right output.
232553
235325
232355
235253
252533
these 2 lines mean if the pid is the parent, then wait for what?
if ((pid=fork())!= 0)
waitpid(pid,NULL,0);
then if it is the child process (fork = 0), then print 3.. correct?
if (fork() == 0)
{ printf("3 "); exit(0); }
As David Schwartz said, the output of this program will consists of some permutation of the digits 2, 3 and 5. No one output is correct, because the output depends on the order in which the processes execute, which is arbitrary.