Operations 6 min read

Master Linux Process Termination: kill, killall, and pkill Explained

Learn how to identify and terminate Linux processes using commands like kill, killall, and pkill, including signal options, PID retrieval methods, and practical examples for both foreground and background tasks, ensuring safe and effective process management on Unix-like systems.

Open Source Linux
Open Source Linux
Open Source Linux
Master Linux Process Termination: kill, killall, and pkill Explained

How to Terminate a Linux Process

If a process runs in the foreground you can stop it with Ctrl+C. For background or invisible processes use dedicated commands.

kill command

The kill command terminates a process by its PID. Syntax:

kill <signal> <PID>
signal

is the termination signal, PID is the process ID.

Common termination signals

SIGHUP (1) : Hangup – sent when the controlling terminal is closed.

SIGINT (2) : Interrupt – sent when the user terminates the process (e.g., Ctrl+C).

SIGKILL (9) : Kill – forces immediate termination, cannot be caught.

SIGTERM (15) : Terminate – polite request to exit; can be ignored but is preferred.

SIGSTOP (19) : Stop – pauses the process, can be resumed later.

Obtaining a Process PID

Use pidof to get the PID from the process name: pidof exact_process_name Example for Java processes:

pidof java
8075 1032

Using kill

To terminate a process, provide its PID and optionally a signal. If no signal is given, kill defaults to SIGTERM (15).

# Start a background sleep process
sleep 120 &
[1] 125686

# Terminate it
kill 125686
[1]+  terminated  sleep 120

You can also specify the signal by name or number, e.g., kill -SIGKILL 125746 or kill -9 125759.

killall command

If you do not know the PID or want to kill all instances of a process, use killall: killall [signal] <process-name> Without a signal, killall sends SIGTERM (15) by default.

# Kill all sleep processes
sleep 120 &
[1] 112351
sleep 2000 &
[2] 112362
killall sleep
[1]-  Terminated  sleep 120
[2]+  Terminated  sleep 2000

pkill command

pkill

is a pattern‑matching alternative to killall. It can filter by user ( -u), exact match ( -x), or signal ( -signal). pkill [options] pattern Example to stop all nginx processes:

pkill nginx
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxKill Commandsignalsprocess terminationkillallpkill
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.