How to make parent wait for all child processes to finish?

后端 未结 3 1067
有刺的猬
有刺的猬 2020-11-27 02:47

I\'m hoping someone could shed some light on how to make the parent wait for ALL child processes to finish before continuing after the fork. I have cleanup code whi

3条回答
  •  自闭症患者
    2020-11-27 03:27

    POSIX defines a function: wait(NULL);. It's the shorthand for waitpid(-1, NULL, 0);, which will suspends the execution of the calling process until any one child process exits. Here, 1st argument of waitpid indicates wait for any child process to end.

    In your case, have the parent call it from within your else branch.

提交回复
热议问题