Problem forking fork() multiple processes Unix

后端 未结 4 1120
走了就别回头了
走了就别回头了 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:48

    Each child process picks up and continues the loop.

    In other words, child 1 is spawned and continues with iteration #2 of loop etc.

    When a process is forked, a copy of the current process is made: the resulting child process continues execution after the fork() call. That's why you must take care of the return code in your logic.

提交回复
热议问题