How to use fork() in unix? Why not something of the form fork(pointerToFunctionToRun)?

前端 未结 8 2124
盖世英雄少女心
盖世英雄少女心 2021-02-06 05:01

I am having some trouble understanding how to use Unix\'s fork(). I am used to, when in need of parallelization, spawining threads in my application. It\'s always s

8条回答
  •  野性不改
    2021-02-06 05:44

    Fork has been with us for a very, very, long time. Fork was thought of before the idea of 'start a thread running a particular function' was a glimmer in anyone's eye.

    People don't use fork because it's 'better,' we use it because it is the one and only unprivileged user-mode process creation function that works across all variations of Linux. If you want to create a process, you have to call fork. And, for some purposes, a process is what you need, not a thread.

    You might consider researching the early papers on the subject.

提交回复
热议问题