Course contentsShow
← Linux
Lesson 11 of 1,8191. Shell Architecture and Process EnvironmentFree lesson

Job Control and the SIGCHLD Signal

Monitor and react to process state changes in background jobs using low-level signal trapping.

In this lesson, you will learn how the shell keeps track of background tasks by listening for specific "status change" notifications from the operating system.

The Problem of Disappearing Jobs

When you run a command in the background (using the & operator), your shell doesn't just forget about it. However, the shell is usually busy waiting for your next keyboard input. If that background process finishes, how does the shell know? If the shell had to constantly ask the kernel, "Is that job done yet?" for every single background process, it would waste a massive amount of computing power.

Enter SIGCHLD

Instead of polling, the kernel uses an event-driven system. Whenever a child process changes state—meaning it either terminates, stops (is suspended), or resumes—the kernel sends a specific signal to the parent process (your shell): SIGCHLD (Signal Child).

Think of SIGCHLD as a "doorbell" that the kernel rings whenever a child process has news to report. When your shell receives this signal, it interrupts what it is doing for a split second to perform a wait() system call. This allows the shell to harvest the exit status of the child, update its internal job table, and perhaps print a message like [1]+ Done to your terminal.

Seeing the Mechanism in Action

While you rarely handle SIGCHLD manually, you can observe the shell reacting to it. Try this:

# Start a process in the background
sleep 10 & 

# The shell notes the job ID and PID.
# Once the 10 seconds pass, the kernel sends SIGCHLD to your shell.
# Your shell catches the signal and displays the status change:
[1]+  Done                    sleep 10

Without the SIGCHLD signal, your shell would have no idea that your background task had completed until you happened to press Enter to show a new prompt. By using this signal, the shell remains responsive and aware of its process environment, allowing you to manage multiple concurrent tasks smoothly while maintaining control over the foreground.

Key Takeaway: The SIGCHLD signal acts as an asynchronous notification from the kernel to the shell, ensuring the shell is immediately alerted whenever a background process changes state or finishes execution.