What exactly does fork return?

后端 未结 8 1152
时光取名叫无心
时光取名叫无心 2020-12-02 13:51

On success, the PID of the child process is returned in the parent’s thread of execution, and a 0 is returned in the child’s thread of e

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 14:14

    fork() is invoked in the parent process. Then a child process is spawned. By the time the child process spawns, fork() has finished its execution.

    At this point, fork() is ready to return, but it returns a different value depending on whether it's in the parent or child. In the child process, it returns 0, and in the parent process/thread, it returns the child's process ID.

提交回复
热议问题