Consider the output of the below program:
int main()
{
int ret;
ret=fork();
ret=fork();
ret=fork();
ret=fork();
if(!ret)
printf("one\n");
else
printf("two\n");
return 0;
}
I am getting the output as:
two
one
two
two
AFAIT, the output should be 8 times one & 8 times two.
Where are the rest one's & two's?
Consider this alternative code which tracks what goes on somewhat better:
Show us the output from this variation and we can see what worked and what failed.
After seeing the alternative output, I got this on my Mac (where
Isis JL:is my prompt andrmkis an alternative implementation ofmake):Note the interleaved prompt — the blank line at the end is where I hit return after the output completed.
Hypothesis:
The output on ideone is not captured after the initial process stops.
Try this alternative, which waits for children to die before exiting:
Output on Mac, once more:
Hypothesis Proven
To the extent you can prove anything… http://ideone.com/zFoLn …
This shows all 16 lines of output. The problem must have been ‘premature termination’.