4 ms·
This probably needs to be fixed in POSIX with the gradual deprecation of fork(2) over decades. If we start now we might be done by 2038. Maybe start by deprecat
by pjc50 8y ago
This probably needs to be fixed in POSIX with the gradual deprecation of fork(2) over decades. If we start now we might be done by 2038. Maybe start by deprecating fork-after-multithreading, since that's extremely hard to get right in the first place.
fork/exec was a convenient hack for singlethreaded small programs on the PDP-11. Its semantics interact badly with all kinds of subsequent features, and it interferes with porting to other operating systems.
- noselasd 8y agoI don't think we'll see the fork/exec semantics going away anyway soon - inheriting privileges/file-descriptors etc. in this way is quite core to all unix like OSs. posix does provide posix_spawn() though, which an OS could implement in a more efficient way than fork()+exec().
- anticensor 8y agoexec() can remain as it is still useful, only fork needs to be deprecated as fork can be emulated by clone in common use cases.
- pjmlp 8y agoClone is a Linux only syscall.
- deleted 8y ago[deleted]
- cryptonector 8y agoIt is usually implemented as vfork()+exec/exit. Some OSes implement posix_spawn() as a system call. IIRC NetBSD has had that, and Solaris 12 has it too.
- trasz 8y agoOSX as well.
- anticensor 8y agoBourne-like shells do not interact well with spawn(2). Their foreground execution semantics require forking.
- DonHopkins 8y agoThere should be a system call called spork(2) that handles both use cases.
- zzzcpan 8y agoFork needs to evolve a bit for capability-based security, but other than that fork is ok. The problem is in concurrent shared memory access, which is extremely hard to get right. And the fix is to deprecate shared memory multithreading altogether. It's too hard to use, too slow, too broken and has no future either way.
- adwn 8y ago> And the fix is to deprecate shared memory multithreading altogether. Not gonna happen without a radically different CPU, OS, and application software paradigm. In other words: extremely unlikely in the next 2-3 decades (at least). > It's too hard to use Agree for most languages. Have you tried Rust? It makes shared memory multi-threading not just much simpler, but also safe. > too slow Very wrong for multi-core CPUs, where message-passing is emulated using shared memory. > too broken What does that even mean? With the right language-enforced mechanism, it is very much non-broken and functional. > and has no future either way. Very wrong, see first paragraph.
- lmm 8y ago> Have you tried Rust? It makes shared memory multi-threading not just much simpler, but also safe. It makes it safe by not letting you share; data is owned explicitly and passed explicitly.
- adwn 8y ago> It makes it safe by not letting you share That is simply wrong. Rust makes it easy and safe to share immutable data – it's the ability to mutate that can't be shared. > data is owned explicitly and passed explicitly Yes, data is owned explicitly, but the permission to read or write the data is somewhat independent of ownership – the owner of an object can grant permission to access the object, and it can pass this permission to other threads without relinquishing ownership.
- steveklabnik 8y ago
- cryptonector 8y agoThis. fork(2) is evil. It is no longer needed. Use posix_spawn(). If you need to spawn child worker processes sharing state with the parent, then pass that state via pipe and tell the child about it via a command-line option. Or something like that. fork(2) should absolutely be deprecated. vfork(2) can stay. It's hard to use, but not actually harder to use safely than fork(2), and has much better performance (no copies, no CoW). vfork(2)'s reputation as nasty is undeserved.