How to Kill a Process by Name in Linux

Find matching process IDs with pgrep and terminate them safely.

Killing by name is convenient, but it can affect more than one process. The safe workflow is to search first, inspect the matches, then send SIGTERM and escalate only when necessary.

Step by step

1 Find matching processes

$ pgrep -af process-name

Shows PIDs and command-line context so you can verify what will be affected.

2 Terminate by name

$ pkill -TERM process-name

Sends SIGTERM to matching processes and gives applications a chance to shut down cleanly.

3 Target a specific user

$ pkill -u username process-name

Limits the match to processes owned by the specified user.

4 Force only after verification

$ pkill -KILL process-name

SIGKILL is a last resort because the process cannot clean up before termination.

Tips worth knowing

Frequently asked questions

What is the difference between kill and pkill?

`kill` targets explicit PIDs; `pkill` selects processes by attributes such as name or user.

How do I kill all processes with a name?

Use `pkill name` only after checking the matches with `pgrep -af name`.

Is pkill -9 safe?

No. SIGKILL is deliberately forceful and should be a last resort after a normal termination request fails.

The commands behind it

kill

Terminate processes politely or forcibly — and understand what -9 really does.

ps

See what is running, find a process ID, and combine with grep to hunt down a program.

systemctl

Start, stop, enable and inspect services — the control panel of modern Linux.

Concepts involved: Process · PID (Process ID)

More how-to guides

Check disk space in Linux

See how much space is left, and find out what is using it.

Extract a .tar.gz archive

Unpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.

Free a port that is already in use

Find which process holds a port and stop it cleanly.

Find and replace text in files

Replace text in one file or across a whole project, safely.