Ch 9 Process Relationships
Terminal Login
Read /etc/ttys, for each terminal fork a process and execute getty to read the login username and initial environment settings. After input completion, execute exec login to read the password, and upon successful authentication, execute the shell to complete the user’s terminal login.
Network connections use pseudo-terminal drivers through the telnetd daemon and telnet client for communication, as if they were hardwired connections.
Process Groups
Each process group has a leader process. The process group ID of the leader process equals its process ID. A process group exists as long as at least one process in the group exists.
A process can only set the process group ID for itself or its child processes. After its child process calls exec, it can no longer change the child’s process group ID.
After fork, if both parent and child call setpgid, it ensures that the process group ID is correctly set regardless of execution order.
Sessions
A session is a collection of one or more process groups.
Several processes connected with the pipe operator | will be grouped together.
Sessions form the foundation for terminal foreground and background implementation. Several process groups within a session can be divided into one foreground process group and one or more background process groups.
Job Control
Job control is supported through job control signals.
Three special characters can cause the terminal driver to generate signals and send them to the foreground process group:
Interrupt character - SIGINT Quit character - SIGQUIT Suspend character - SIGTSTP
Only the foreground job receives terminal input. If a background job attempts to read from the terminal, this is not an error. The terminal driver detects this situation and sends SIGTTIN to the background job, which typically stops the background job, and the shell notifies the user. Switching to the foreground process group sends the continue signal SIGCONT to that process group.
Shell
The shell first forks a copy of itself, then forks a process for each command in the pipeline. The processes of these commands and the shell all belong to a foreground process group.