5 ms·
(This is a bit of a tangent, apologies.) > fork(2) makes a lot more sense when you realize its heritage. I think it only makes sense when you consider its her
by Quekid5 5y ago
(This is a bit of a tangent, apologies.)
> fork(2) makes a lot more sense when you realize its heritage.
I think it only makes sense when you consider its heritage. It has ALL the wrong defaults for what it's almost always used for these days: running a subprocess.
It copies "random" kernel data structures like open FDs, etc. and you have to be very careful about closing the ones you don't want to be inherited, etc. etc. It may copy things that weren't even a relevant concept when you wrote your program.
The correct thing to do is to very explicit about what you want to pass onto the subprocess and to choose safe defaults for programs compiled against the old API when you extend it. (Off the top of my head, the only thing I'd want to be automatically inherited by default would be the environment and CWD.)
It's 100% the wrong API for spawning processes.
Now, I don't think afork() solves any of these problems, AFAICT. But my personal perspective is that fork() and its derivatives are the wrong starting point in the first place for what they are used for in 99% of all cases.
- cryptonector 5y agoafork() could do some things differently. The point of afork() is to be able to spawn child processes (that will exec-or-_exit) faster.
- monocasa 5y agoPractically, this is the struct you have to fill in if you don't use clone or fork. https://github.com/torvalds/linux/blob/719fce7539cd3e186598e2aed36325fe892150cf/include/linux/sched.h#L728 https://github.com/torvalds/linux/blob/719fce7539cd3e186598e... IMO clone looks a lot better than screwing with that giant struct and all of the kernel bugs that would exist from validating every goofy way those options could be setup wrong by user space.
- twic 5y agoThe behaviour of subprocesses inheriting resources like file descriptors is absolutely bizarre. Why on earth would you want this to be the default?! But we're so used to it, we think it's normal.
- cryptonector 5y agoWindows did the opposite and that still resulted in problems.