In the fork case the OS can use 'copy-on-write' semantics for the memory pages associated with both new processes to ensure that each one gets their own copy of the pages they subsequently modify.
socket_accept()
fork()
if (child)
handleRequest()
else
goOnBeingParent()
Therefore the implementation of fork had to be fast and lots optimizations have been implemented over time.
Microsoft endorsed CreateThread or even fibers instead of creating new processes and usage of interprocess communication. I think it's not "fair" to compare CreateProcess to fork since they are not interchangeable. It's probably more appropriate to compare fork/exec to CreateProcess.
基于 Unix 的系统最初是多用户系统和服务器。特别是对于后者,分离处理特定作业的进程(例如邮件或 http 守护进程)并不少见(例如处理一个传入连接)。这样做的一个重要因素是廉价的 fork方法(正如 Rob Walker (47865)所提到的,最初对新创建的进程使用相同的内存) ,这非常有用,因为新进程立即拥有它所需要的所有信息。
It is clear that at least historically the need for Unix-based systems to have fast process creation is far greater than for Windows systems. I think this is still the case because Unix-based systems are still very process oriented, while Windows, due to its history, has probably been more thread oriented (threads being useful to make responsive applications).
Disclaimer: I'm by no means an expert on this matter, so forgive me if I got it wrong.
NT 从一开始就是为多用户设计的,所以这不是一个真正的原因。然而,您是对的,进程创建在 NT 上的作用不如在 Unix 上重要,因为与 Unix 相比,NT 更青睐多线程而不是多处理。
Rob, it is true that fork is relatively cheap when COW is used, but as a matter of fact, fork is mostly followed by an exec. And an exec has to load all images as well. Discussing the performance of fork therefore is only part of the truth.
在讨论进程创建的速度时,区分 NT 和 Windows/Win32可能是一个好主意。就 NT (即内核本身)而言,我不认为进程创建(NtCreateProcess)和线程创建(NtCreateThread)的速度比一般的 Unix 慢得多。可能还有一些其他的原因,但是我看不出这里性能差异的主要原因。
All that plus there's the fact that on the Win machine most probably an antivirus software will kick in during the CreateProcess... That's usually the biggest slowdown.
I worked with an embedded system that was quite temperamental once upon a time, and one day looked at it and realized it was a cavity magnetron, with the electronics in the microwave cavity. We made it much more stable (and less like a microwave) after that.
In addition to the out-of-process LPC calls to CSRSS, in XP and later there is an out of process call to the application compatibility engine to find the program in the application compatibility database. This step causes enough overhead that Microsoft provides a group policy option to 禁用 WS2003上的兼容性引擎 for performance reasons.