3 ms·
> Can you please elaborate on why those two ideas are "horrible"? The problems with fork are thoroughly explained by this Microsoft paper: https://www.microso
by matheusmoreira 4y ago
> Can you please elaborate on why those two ideas are "horrible"?
The problems with fork are thoroughly explained by this Microsoft paper:
https://www.microsoft.com/en-us/research/uploads/prod/2019/04/fork-hotos19.pdf https://www.microsoft.com/en-us/research/uploads/prod/2019/0...
As for asynchronous signals, they are a completely broken concept and implementation.
It's not safe to do pretty much anything in a signal handler other than setting a flag and returning. You cannot use any non-reentrant function which eliminates pretty much everything useful, including the vast majority of standard library functions.
The system drops events. Signals are essentially a pending delivery flag in the kernel, signaling a process just sets the flag to 1 so there's no difference between doing it once and 10000 times.
Was in a system call when your process was signaled? It will be interrupted or cancelled. It returns EINTR and your code needs robust retrying logic to handle such a case. I've seen code that couldn't handle it and crashed.
There's race conditions everywhere. Signals can arrive while you're handling other signals, you need to block block them if you don't want that. Every thread has its own signal handling behavior. Signals sent to a process are handled by "any" thread. I remember reading in some standard that using signals in multithreaded programs was undefined behavior. Who even knows what's going to happen?
The only borderline sane way to handle signals is with file descriptors: you block traditional signal handling on all threads and set up a signalfd that you can epoll along with everything else on a thread dedicated to the event loop. Even this is pretty bad:
https://ldpreload.com/blog/signalfd-is-useless https://ldpreload.com/blog/signalfd-is-useless
https://news.ycombinator.com/item?id=9564975 https://news.ycombinator.com/item?id=9564975
- up2isomorphism 4y agoSo M$ write this to convince people their CreateProcess is better than fork? Not smart. Thinking signal sucks is just because people trying relying on it to do something it is not designed to do. You can not complain a pile of wood is not a table.
- jolmg 4y agoYou got me. That is quite horrible.
- throwawaylinux 4y agoAsynchronous processor interrupts have analogues to basically all these issues that signals do. Signals are certainly a pain to implement and get right, but people seem to think they're something that they aren't, or expect them to be used for something they can't do. Clearly signals aren't a message passing scheme, they're a notification system. And obviously taking an asynchronous interrupt needs to use reentrant code. As for the fork paper, seems like a typical academic type of critique. "Fork today is a convenient API for a single- threaded process with a small memory footprint and simple memory layout that requires fine-grained control over the execution environment of its children but does not need to be strongly isolated from them." I.e., exactly what it is good for and used for. And it goes on "Fork is incompatible with a single address space. Many modern contexts restrict execution to a single address space, including picoprocesses [42], unikernels [ 53], and en- claves [ 14]." And talking about heterogeneous address spaces, and all other things academics love but nobody really uses. They also make pretty outlandish claims "Fork infects an entire system." based on the Windows implementation where the Win32 API and kernel explicitly do not implement fork. And it's provocative language "infects" -- the Linux kernel fork implementation is maybe a thousand lines of C code. And that does not constrain it or prevent it offering several of the suggested alternatives. K42 was also a failure of a research operating system, and another microkernel (surprise). Turns out (as usual) that designing a system around some latest craze or fad in technology no matter how good (RCU and other lock free algorithms) rather than designing it to deal with workloads that people actually use, is still the recipe for disaster and one of the main causes of second system syndrome.
- robocat 4y agoGood discussion both pro and against the paper here: https://lwn.net/Articles/785430/ https://lwn.net/Articles/785430/ Fork causes huge complications. I summarised some of the paper here https://news.ycombinator.com/item?id=31702952 https://news.ycombinator.com/item?id=31702952 Edit: I imagine forking and signal handlers don’t compose well, and I also would hate to have to think how forking and SCM_RIGHTS interfere with each other: https://googleprojectzero.blogspot.com/2022/08/the-quantum-state-of-linux-kernel.html https://googleprojectzero.blogspot.com/2022/08/the-quantum-s...