Task

In your shell, you can use kill -XXX PID, where XXX is the human-friendly suffix of the desired signal, to send any signal to the process with process id PID. For example, kill -TERM PID sends a SIGTERM to the process with process id PID.

In C, you can use the sigaction system call to change how signals are handled by the current process. The shell should basically ignore most of these signals, whereas the shell’s subprocesses should respond with the default action. For example, while running child processes, the shell should ignore SIGTTOU, SIGTTIN, SIGTSTP, but the subprocesses should not.

Beware: forked processes will inherit the signal handlers of the original process. Reading about sigaction and signal will provide more information. Be sure to check out the SIG_DFL and SIG_IGN constants.

Please also look at Process Groups and Terminal Signaling for an explanation of process groups. For more information on process groups and terminal signaling, please go through this tutorial.

Your task is to ensure that each process you start in a line of commands is in its own process group, the process group id should be the process id of the first process launched. When you start a process (or several of them in one line), the process group should be placed in the foreground (see the tcsetpgrp function). Stopping signals should only affect the foregrounded program, not the backgrounded shell.