I have a SIGCHILD handler installed in my shell. Let's say I'm using waitpid to wait for a foreground process to terminate so that I can reap it.
From what I know, waitpid suspends the current process and waits for the given process to terminate, yes?
What if one of the background processes terminated while my shell is waiting for the foreground process? When will my shell reap the terminated background process? How can I make sure that the background process will be reaped immediately?