Problem forking fork() multiple processes Unix

后端 未结 4 1155
走了就别回头了
走了就别回头了 2021-02-01 23:28

So I have this function that forks N number of child processes. However it seems to be forking more than specified. Can you tell me what I\'m doing wrong? Thanks



        
4条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 23:58

    The fork() call spawns a new process which begins its execution at the exact same point where the fork occurred. So, it looks like fork "returns twice"

    What's happening here is that your fork() call returns twice, so both the parent and child process continue looping and spawning new processes. Each child (of both the original parent and child) then forks again, repeatedly doubling the number of processes...

提交回复
热议问题