In this lesson, you will learn what happens to a group of processes when their parent session is forcibly terminated, a state known as "orphanage."
The Relationship Hierarchy
To understand orphanage, visualize a terminal session as a parent container. Inside this session, you might have several process groups—like a pipeline of commands (grep | sort | uniq). The session leader (usually your shell) tracks these groups.
Normally, when you exit your shell cleanly, it sends a SIGHUP (hangup signal) to all processes in its foreground process group, telling them to clean up and shut down. But what happens if the terminal window is forcibly closed or the session leader is killed abruptly?
The Orphanage Trigger
When a session leader dies suddenly, the kernel recognizes that the processes remaining in that session are essentially "orphaned." They no longer have a controlling terminal to talk to, and their parent leader is gone.
If these orphaned processes are in the foreground, they can no longer receive input from the (now dead) terminal. To prevent these processes from becoming "zombie" relics consuming system resources or trying to write to a disconnected terminal, the kernel performs a cleanup:
- The orphaned process group is sent a
SIGHUPto notify them of the disconnection. - If they continue to run, they become detached from the TTY entirely.
- They are effectively "re-parented" to
init(or your user's systemd manager), moving them into the background.
Seeing it in Action
Imagine running a long background task in a terminal window:
# Start a process that ignores hangups
nohup sleep 1000 &
If you kill your terminal emulator window, the sleep command doesn't die. Because it was detached from the terminal session's lifecycle (via nohup), it survives the session orphanage. It is no longer part of your interactive shell’s process group; it is now an independent orphan process managed by the system.
Key Takeaway: When a session leader is forcibly terminated, the kernel sends a SIGHUP to the remaining process groups and orphans any survivors, detaching them from the destroyed controlling terminal.