Please consider the following fork()/SIGCHLD pseudo-code.
// main program excerpt
for (;;) {
if ( is_time_to_make_babie
Simplest solution would be to block SIGCHLD signal before fork() with sigprocmask() and unblock it in parent code after you have processed the pid.
If child died, signal handler for SIGCHLD will be called after you unblock the signal. It is a critical section concept - in your case critical section starts before fork() and ends after children.add().