When the foreground job terminates or is stopped, the SIGCHLD handler executes as usual.
The handler changes the state of the foreground process from foreground to either stopped or undefined (if it was terminated).
If the handler does this, the shell can wait for a foreground process by repeatedly checking if the state of the foreground process has changed.