Why is creating a new process more expensive on Windows than Linux?

后端 未结 10 697
情深已故
情深已故 2020-11-27 11:35

I\'ve heard that creating a new process on a Windows box is more expensive than on Linux. Is this true? Can somebody explain the technical reasons for why it\'s more expen

10条回答
  •  感情败类
    2020-11-27 12:16

    In addition to the answer of Rob Walker: Nowadays you have things like the Native POSIX Thread Library - if you want. But for a long time the only way to "delegate" the work in the unix world was to use fork() (and it's still prefered in many, many circumstances). e.g. some kind of socket server

    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.

提交回复
热议问题