Fork and wait - how to wait for all grandchildren to finish

You can't. Either make your child process wait for its children and don't exit until they've all been waited for or fork all the children from the same process.


See this answer how to wait() for child processes: How to wait until all child processes called by fork() complete?

There is no way to wait for a grandchild; you need to implement the wait logic in each process. That way, each child will only exit after all it's children have exited (and that will then include all grandchildren recusively).

Tags:

C