3 ms·
Fork is simple, but not easy.
by qznc 10y ago
Fork is simple, but not easy.
- the_mitsuhiko 10y agoWhat makes for simple? I really need to understand this. I implemented fork many years ago for a university operating system and nothing about either the implementation nor the usage is simple. I use fork on a daily basis and the POSIX version of it is insanely complex for everybody involved.
- qznc 10y ago> I implemented fork many years ago for a university operating system and nothing about either the implementation nor the usage is simple Me too. I found it simple: Create new child process, copy the address space, copy the instruction pointer, let it run. If you want to improve performance via copy-on-write, it gets more complex to implement. If you combine it with other features like threads, mmap, limits, etc use becomes complex, but the mechanism itself is simple. You might be able to design an easy variant of fork, which handles threads, mmap, limits, etc in a sane way, but that would not be simple anymore. Fork is actually a good example, why simple and easy are different concepts and why it is really hard to achieve both.
- the_mitsuhiko 10y ago> Me too. I found it simple: Create new child process, copy the address space, copy the instruction pointer, let it run. Even in the total absence of threads (which you never have on a modern OS) you already fucked up. Because you did not account for file handles, signal handling, pid management etc. fork() even on the simplest real world operating system is a massive pain for the OS.