This should do the job, if you set your function as a handler for SIGCHLD.
However, SIGCHLD can be send to parent process not only after the child exited. Some other events are signaled this way as well (for instance when the child is stopped). See man wait(3) for detailed explanation.