After the fork you've got two different processes vying for the CPU, and which one gets it is undefined behaviour. So it looks like that version of Linux favours the child (I can see some sence in that, since often the child will exec something else anyway and block on IO, while the parent will simply wait for the child). And that version of MacOS doesn't seem to favour either, just throws them both at the scheduler and see what sticks. As always with undefined behaviour, if your (not you personally) code depends on it, your code is wrong, even if it happens to work on your particular system on the particular day you tested it on. (For instance, under heavy load it might be entirely different.) | [reply] |