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.