In fork() which will run first, parent or child?

前端 未结 2 504
有刺的猬
有刺的猬 2020-12-04 02:01

When the following code runs, I understand the parent and child both will run in parallel immediately after fork() is called.

#include 

        
2条回答
  •  离开以前
    2020-12-04 02:44

    Apparently whatever scheduler you're running decides, and it can vary.

    I can say from experience that if you assume that one of the two processes always runs first, you will introduce some very subtle race conditions. Either synchronize on something, like a special message on the pipe, or don't assume that either one runs first.

提交回复
热议问题