CreateThread vs fork()

前端 未结 6 1167
余生分开走
余生分开走 2020-12-20 23:05

Do we have any sort of relationship between fork() and CreateThread? Is there anything that CreateThread internally calls fork()?

6条回答
  •  旧时难觅i
    2020-12-20 23:18

    The Windows and Unix process model is fundamentally very different, so there is no way of directly mapping the API from one on top of the other.

    fork() clones the current process into two. In the parent process, fork() returns the pid, and in the child it returns 0. This is typically used like this:

    int pid;
    if (pid = fork()) {
        // this code is executed in the parent
    } else {
        // this code is executed in the child
    }
    

    Cygwin is an emulation layer for building and running Unix applications on Windows which emulates the behavior of fork() using CreateProcess().

提交回复
热议问题