Course contentsShow
← Linux
Lesson 493 of 1,8195. Process Management and SignalingFree lesson

Handling SIGTERM vs SIGKILL

Differentiate between graceful shutdown requests and immediate kernel-level termination.

In this lesson, you will learn how to distinguish between a polite request to stop a process and a forceful, immediate termination by the kernel.

The Polite Request: SIGTERM (Signal 15)

When you run the command kill <PID>, Linux sends a SIGTERM signal to that process. Think of this as a polite request to "please shut down."

Because it is a signal, the application has the ability to "catch" it. Well-behaved programs use this time to perform a graceful shutdown: they finish writing data to disk, close network connections, release temporary files, and inform other processes that they are leaving. This prevents data corruption and ensures that system state remains consistent.

The Forceful End: SIGKILL (Signal 9)

Sometimes, a process is "stuck"—perhaps it is trapped in an infinite loop or refusing to respond to the SIGTERM request. In these cases, you use kill -9 <PID>, which sends SIGKILL.

Unlike SIGTERM, SIGKILL cannot be caught, ignored, or handled by the process. The process is not even given a chance to run any cleanup code. Instead, the Linux kernel immediately removes the process from the CPU scheduler and reclaims its memory and resources. Because the process is never notified that it is being terminated, it cannot perform any cleanup.

A Quick Comparison

FeatureSIGTERM (15)SIGKILL (9)
IntentRequest to stop gracefullyImmediate termination
HandlingCan be caught or ignoredCannot be caught or ignored
Data SafetyHigh (cleanup occurs)Low (potential for data loss)
UsageAlways try this firstOnly use as a last resort

Example workflow:

  1. Try kill 1234 (sends SIGTERM).
  2. Wait a few seconds for the process to exit.
  3. If the process is still running, escalate to kill -9 1234 (sends SIGKILL).

Key Takeaway: Use SIGTERM as your primary tool to allow applications to save state and clean up, reserving SIGKILL as an emergency measure for unresponsive processes when all other options fail.