5 ms·
Amusingly vfork semantics differ across OSes. This program prints 42 in Linux but 1 on Mac: https://godbolt.org/z/jn7Gaf5Me https://godbolt.org/z/jn7Gaf5Me beca
by ridiculous_fish 5y ago
Amusingly vfork semantics differ across OSes. This program prints 42 in Linux but 1 on Mac: https://godbolt.org/z/jn7Gaf5Me https://godbolt.org/z/jn7Gaf5Me because on Linux they share address space.
- butterisgood 5y agoI am pretty sure Mac OS doesn't COW fork(), and that the address space is copied. At least it was the last time I looked. FreeBSD and Linux both seem to COW. Perhaps there's a reason vfork is different too.
- ridiculous_fish 5y agoMy (very possibly wrong) understanding is that xnu does CoW fork but doesn't overcommit, meaning that memory must be reserved (perhaps in swap) in case the pages need to be duplicated. There's other complications relating to inheriting Mach ports and the mach_task <-> BSD process "duality" in xnu, which Linux doesn't have. I'd love for someone to chime in who knows more about how this stuff works.
- cryptonector 5y agoHopefully someone at Apple will see this post and be convinced to restore vfork() and un-obsolete it.
- cryptonector 5y agoUnfortunately there was this paper from the 80s titled "vfork() Considered Dangerous", which led to BSDs removing vfork(), and then later it was re-added because that paper was clearly quite wrong. But the news hasn't quite filtered through to Apple, I guess.