When processes terminate, they should be cleaned up in order to avoid accumulating zombie processes.
A SIGCHLD signal is sent to the shell when a child is terminated or changes state to stopped.
The shell can/should implement a handler for SIGCHLD signals in order to clean up these terminated processes.
This handler
- can use waitpid with option = WUNTRACED or option = WUNTRACED | WNOHANG.
- If waitpid returns because a process has stopped, the job state should be set to ST. This is important!
- If waitpid returns because a process has exited, the job entry should be deleted (use the deletejob function).
- If the job terminated because it received a signal, a message
should also be printed.
(Check the expected messages by running the driver on the test files.)