Skip to content

The kill Command — Terminating Processes in Linux

The kill command is used to send signals to running processes. Although its name suggests that it always terminates processes, kill can send many different signals, allowing you to gracefully stop, pause, resume, or forcefully terminate applications. It is one of the most important commands for Linux administrators, DevOps engineers, Cloud Architects, and Site Reliability Engineers (SREs).


Learning Path

Linux Mastery → Module 6: Process Management → Lesson 7

Difficulty: Beginner → Intermediate

Reading Time: 60 Minutes

Course Progress

Course: Linux Mastery

Module: Process Management

Lesson: 7 of 10


What You'll Learn

After completing this lesson, you'll be able to:

  • Understand the kill command
  • Find Process IDs (PIDs)
  • Send signals to processes
  • Gracefully terminate applications
  • Forcefully terminate processes
  • Kill multiple processes
  • Troubleshoot stuck applications
  • Apply process termination safely in production

Prerequisites

Complete:

  • Module 1 – Linux Fundamentals
  • Module 2 – Linux Command Line Essentials
  • Module 3 – Text Processing
  • Module 4 – File Management and Permissions
  • Module 5 – Users and Groups
  • Module 6 Lessons 1–6

Why Learn kill?

Imagine:

  • A Java application stops responding.
  • NGINX hangs.
  • A backup process never finishes.
  • A Python script enters an infinite loop.

How do you stop the process?

Linux provides the:

kill

command.


What is kill?

Despite its name,

kill does not always kill a process.

Instead,

it sends a signal to a process.

The process decides how to respond depending on the signal.


Basic Syntax

kill PID

Example:

kill 2456

By default,

this sends:

SIGTERM (Signal 15)

Finding the PID

Before terminating a process,

find its PID.

Example:

ps -ef | grep nginx

or

pgrep nginx

Example:

2456

Terminate:

kill 2456

Graceful Termination

Default signal:

SIGTERM

Signal 15

Example:

kill 2456

The application has an opportunity to:

  • Save data
  • Close files
  • Release resources
  • Shut down cleanly

This is the preferred method.


Forceful Termination

Some processes ignore SIGTERM.

Use:

kill -9 PID

Example:

kill -9 2456

This sends:

SIGKILL

Signal 9

The process is terminated immediately by the kernel and cannot clean up resources.

Use only as a last resort.


Kill Multiple Processes

kill PID1 PID2 PID3

Example:

kill 2456 2480 2510

Kill by Signal Name

Instead of numbers,

use names.

Example:

kill -SIGTERM PID

kill -SIGKILL PID

or

kill -TERM PID

kill -KILL PID

Display Available Signals

kill -l

Example:

HUP

INT

QUIT

KILL

TERM

STOP

CONT

...

Verify the Process

Before:

ps -p PID

Terminate:

kill PID

Verify again:

ps -p PID

If no output is displayed,

the process has exited.


Common Signals

Signal Number Purpose
SIGTERM 15 Graceful termination
SIGKILL 9 Immediate termination
SIGINT 2 Interrupt (Ctrl + C)
SIGSTOP 19 Pause a process
SIGCONT 18 Resume a paused process
SIGHUP 1 Reload or restart configuration (application-dependent)

We'll learn signals in detail in the next lesson.


Common Commands

Terminate process.

kill PID

Force termination.

kill -9 PID

List signals.

kill -l

Terminate multiple processes.

kill PID1 PID2

Terminate gracefully.

kill -15 PID

Real Production Examples

Stop NGINX worker.

kill PID

Terminate a stuck Python script.

kill -9 PID

Stop a backup job.

kill PID

Terminate a runaway Java process.

kill -9 PID

Production Perspective

The kill command is used for:

  • Hung applications
  • High CPU processes
  • Memory leaks
  • Infinite loops
  • Failed deployments
  • Troubleshooting
  • Maintenance
  • Incident response

Always attempt graceful termination before using SIGKILL.


Hands-on Lab

Task 1

Start a process.

sleep 600 &

Task 2

Find its PID.

ps -ef | grep sleep

Task 3

Terminate gracefully.

kill PID

Task 4

Verify termination.

ps -p PID

Task 5

Start another process.

sleep 600 &

Task 6

Force termination.

kill -9 PID

Task 7

List available signals.

kill -l

Task 8

Terminate multiple test processes.

kill PID1 PID2

Command Deep Dive

Command Purpose Production Example
kill PID Gracefully terminate Application shutdown
kill -9 PID Force termination Hung processes
kill -15 PID Send SIGTERM Controlled shutdown
kill -l List signals Signal reference
ps -p PID Verify process Troubleshooting

Production Troubleshooting Scenario

Scenario

A Java application begins consuming 100% CPU.

Investigation:

top

ps -ef | grep java

The application stops responding.

First attempt:

kill PID

The application does not exit.

Second attempt:

kill -9 PID

The process terminates immediately.

The administrator then investigates the application logs to determine the root cause rather than relying on forceful termination as a permanent solution.


Best Practices

  • Always verify the PID before terminating a process.
  • Use SIGTERM (kill) before SIGKILL (kill -9).
  • Confirm the process owner and purpose before terminating it.
  • Investigate why a process became unresponsive.
  • Avoid using kill -9 unless graceful termination fails.

Common Mistakes

❌ Using kill -9 as the first option.

✅ Always try graceful termination first.


❌ Killing the wrong process due to an incorrect PID.

✅ Double-check the PID before sending signals.


❌ Terminating critical system processes.

✅ This can destabilize the operating system or interrupt running services.


Interview Questions

Beginner

  1. What does the kill command do?
  2. Which signal is sent by default?
  3. What is the difference between kill and kill -9?
  4. How do you list available signals?

Intermediate

  1. Why is SIGTERM preferred over SIGKILL?
  2. How do you terminate multiple processes?
  3. How do you verify that a process has terminated?
  4. Why might a process ignore SIGTERM?

Architect Level

  1. How would you safely terminate a production application?
  2. Why should SIGKILL be used only as a last resort?
  3. How would you investigate an application that repeatedly requires forceful termination?

Summary

In this lesson, you learned:

  • The kill command
  • Process termination
  • Graceful shutdown
  • Forceful termination
  • Process signals
  • Production troubleshooting
  • Best practices

The kill command is a fundamental Linux administration tool. It provides controlled communication with running processes through signals, allowing administrators to terminate or manage applications safely. Understanding when to use graceful versus forceful termination is essential for maintaining stable production systems.


Key Takeaways

  • kill sends signals to processes.
  • The default signal is SIGTERM (15).
  • Use SIGTERM for graceful shutdowns.
  • Use SIGKILL (9) only when a process cannot terminate normally.
  • Verify the PID before sending signals.
  • Always investigate the root cause of hung or unresponsive processes.

What's Next?

Linux Signals — Process Communication and Control

You'll explore:

  • What signals are
  • Common Linux signals
  • Signal numbers and names
  • Signal handling
  • Sending signals with kill
  • Process communication
  • Production use cases

Understanding signals will give you deeper insight into how Linux processes communicate and respond to system events.