This function handles children that have terminated or stopped!
Care must be taken since several children could terminate at once, or several additional background children could terminate while the shell is in this handler.
Since there is only one bit in the pending signal mask for SIGCHLD, there is a danger of missing this event for one or more children.
To avoid accumulating zombie children, the shell must call waitpid to clean up terminated children.
The trick is keep calling waitpid in a loop until no more children have stopped or terminated.
How do you do all this? You have to carefully understand the options for waitpid.