Why do processes I fork get systemd as their parent?

前端 未结 3 1396
死守一世寂寞
死守一世寂寞 2021-01-13 05:15

I am learning fork() in Linux, and here is my program:

  1 #include 
  2 #include 
  3 #include 
  4 int main(         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-13 06:03

    I suppose that, sometimes, a race condition happens, and the parent dies before the child. Hence, the child becomes children from init process. In your case, that must be systemd.

    Anyway, be advised that running fork(); fork(); will produce 4 processes, which is (probably) not what you intend. Use control structure as you did with the first one to have fine control on the behaviour of your program.

提交回复
热议问题