How to wait until all child processes called by fork() complete?

前端 未结 5 813
北恋
北恋 2020-12-08 03:28

I am forking a number of processes and I want to measure how long it takes to complete the whole task, that is when all processes forked are completed. Please advise how to

5条回答
  •  暖寄归人
    2020-12-08 03:36

    Call wait (or waitpid) in a loop until all children are accounted for.

    In this case, all processes are synchronizing anyway, but in general wait is preferred when more work can be done (eg worker process pool), since it will return when the first available process state changes.

提交回复
热议问题