In this lesson, you will learn how Linux organizes groups of processes into sessions and connects them to specific terminal interfaces for user interaction.
What is a Session?
Think of a Session as a logical container for related processes, usually starting when you log into the system. Every process belongs to a Process Group, and every Process Group belongs to a Session. You can view these relationships using the ps command with specific flags:
ps -eo pid,pgid,sid,tty,cmd
In this output:
PIDis the process ID.PGIDis the Process Group ID.SIDis the Session ID.TTYshows the controlling terminal.
The Role of the Controlling Terminal
A Controlling Terminal (tty) acts as the bridge between a human user and a session. When you open a terminal window, that device becomes the controlling terminal for the shell process running inside it. Any child process spawned by that shell inherits the same SID and TTY.
This relationship is critical for job control. When you press Ctrl+C in your terminal, the terminal driver sends a SIGINT signal to every process in the foreground process group of that session. If a process does not have a controlling terminal (like a background daemon), it remains unaffected by these user-initiated keyboard signals.
Why Does This Matter?
Processes within a session share the same SID. This allows the kernel to track which processes belong to which "login" context. If you close your terminal window, the kernel sends a SIGHUP (Hangup) signal to all processes associated with that session. This is the mechanism that ensures your background tasks and shells terminate properly when you log out. If you want a process to survive a logout, you must detach it from the session, often by using tools that allow a process to run in its own session context, disconnected from the tty that started it.
Key Takeaway: Sessions group related processes together, and the controlling terminal acts as the primary communication gateway, ensuring that user interrupts are propagated correctly to all members of the session.