News for hackers. Stuff that matters.
Re:A future for fork(2) by pjc50 on Friday October 05, 2018 @08:13AM (#18147457)
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.

Re:A future for fork(2) by noselasd on Friday October 05, 2018 @08:48AM (#18147678)
I 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().

Re:A future for fork(2) by cryptonector on Friday October 05, 2018 @12:26PM (#18149423)
It 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.

Re:A future for fork(2) by trasz on Saturday October 06, 2018 @07:43AM (#18154634)
OSX as well.
Re:A future for fork(2) by anticensor on Friday October 05, 2018 @09:08AM (#18147775)
exec() can remain as it is still useful, only fork needs to be deprecated as fork can be emulated by clone in common use cases.
Re:A future for fork(2) by pjmlp on Friday October 05, 2018 @09:37AM (#18147983)
Clone is a Linux only syscall.
Re:A future for fork(2) by anticensor on Friday October 05, 2018 @09:07AM (#18147762)
Bourne-like shells do not interact well with spawn(2). Their foreground execution semantics require forking.
Re:A future for fork(2) by DonHopkins on Friday October 05, 2018 @11:29AM (#18148906)
There should be a system call called spork(2) that handles both use cases.
Re:A future for fork(2) by cryptonector on Friday October 05, 2018 @12:25PM (#18149414)
This.

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.

Re:A future for fork(2) by zzzcpan on Friday October 05, 2018 @09:42AM (#18148018)
Fork 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.
Re:A future for fork(2) by adwn on Friday October 05, 2018 @10:48AM (#18148556)
> 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.

Re:A future for fork(2) by lmm on Friday October 05, 2018 @12:34PM (#18149508)
> 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.

Re:A future for fork(2) by adwn on Friday October 05, 2018 @01:45PM (#18150114)
> 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.

Re:A future for fork(2) by steveklabnik on Friday October 05, 2018 @01:52PM (#18150177)
> it's the ability to mutate that can't be shared.

So, I do think you're more right than your parent, but I also think this formulation misses important things.

Rust only lets you share when you cannot cause a data race. A type like Mutex lets you share something that's mutable, because the mutex is guarding the sharing. Functions like split_at_mut let you mutably share disjoint parts of a slice.