If I have a process, and I clone it, is the PID the same?

前端 未结 5 1496
南方客
南方客 2020-12-20 05:25

Just a quick question, if I clone a process, the PID of the cloned process is the same, yes ? fork() creates a child process where the PID differs, but everything else is th

5条回答
  •  被撕碎了的回忆
    2020-12-20 06:06

    Not quite. If you clone a process via fork/exec, or vfork/exec, you will get a new process id. fork() will give you the new process with a new process id, and exec() replaces that process with a new process, but maintaining the process id.

    From here:

    The vfork() function differs from fork() only in that the child process can share code and data with the calling process (parent process). This speeds cloning activity significantly at a risk to the integrity of the parent process if vfork() is misused.

提交回复
热议问题