How to Kill Processes by Name in Linux - pkill and killall

Опубликовано: 19 Март 2026
на канале: LinuxHowTo
42
0

In this video, we’ll show you how to kill processes by name in Linux using pkill and killall. We’ll cover how to find processes, kill them gracefully or forcefully, and ensure you only target the processes you intend to. Whether you’re dealing with frozen applications or need to stop background services, these commands will help you manage your system more effectively. Let’s dive into the details and master these essential Linux commands!

Learn:

1. Find the Process First

Search for process by name:
ps aux | grep chrome

More detailed search:
pgrep -l chrome

Sample Output:

user 1234 0.5 2.1 /usr/bin/chrome
user 5678 0.2 1.8 /usr/bin/chrome

2. Kill by Name (Simple Method)

Kill all processes with "chrome" in name:
pkill chrome
Kill exactly matching process name:

pkill -x chrome

3. Kill by Name with Signal

Graceful shutdown (politely ask to close):
pkill -TERM chrome

Force kill (when app is frozen):
pkill -KILL chrome
Or use numbers (9 = force kill):
pkill -9 chrome

4. Kill by Exact Process Name

Kill only exact matches (safer):
killall chrome

Force kill exact matches:
killall -9 chrome

5. Kill Processes Owned by You

Only kill your own processes:
pkill -u $USER chrome

Kill all your browser processes:
pkill -u $USER firefox
pkill -u $USER chrome
pkill -u $USER opera

6. Kill Remote Processes (SSH)

Check what will be killed first (safety check):
ssh user@server "pgrep -l apache2"

Then kill the process remotely if it's correct:
ssh user@server "pkill apache2"
Safety note: Always verify with pgrep before pkill to avoid stopping important services.

Check first — see which processes will be affected:
ssh user@server "pgrep -l 'apache2|mysql|nginx'"

Then kill them all in one go:
ssh user@server "pkill -f 'apache2|mysql|nginx'"

Real-World Examples:

Fix Frozen Browser

Find browser processes:
ps aux | grep -i firefox

Kill all firefox processes:
pkill firefox

If still frozen, force kill:
pkill -9 firefox

Stop Background Services
Stop a specific service:
pkill nginx

Stop database:
pkill mysql

Stop multiple services:
pkill nginx && pkill mysql

Safety First: Check Before Killing!
Always verify first:
ps aux | grep process_name
pgrep -l process_name

See process tree to understand dependencies:
pstree -p | grep process_name

Kill Signals Explained:

Signal Number Effect
TERM 15 Politely ask to exit (default)
KILL 9 Force kill immediately
HUP 1 Reload configuration
INT 2 Interrupt (like Ctrl+C)

Quick Reference:

Find process
ps aux | grep name

Kill politely (like -TERM or -15)
pkill name

Kill forcefully (like -KILL)
pkill -9 name

Kill exact match
killall name

Kill your processes only
pkill -u $USER name

✅ Common Use Cases:
Frozen application → pkill -9 app_name
Too many tabs open → pkill chrome
Service won't restart → pkill -9 service_name

⚠️ Warning:
Don't kill system processes unless you know what they do.
Save your work before killing applications.
Use -9 (KILL) only when necessary - can cause data loss.

✅ Pro Tips:
Always Verify: Use pgrep or ps aux to verify the process before killing it.
Graceful Shutdown: Use TERM signal first to allow processes to clean up.
Remote Management: Use SSH to manage processes on remote servers safely.

GitLab Link: You can find the Tutorial files at this GitLab link: https://gitlab.com/hatem-badawi/linux....

Hit subscribe for more Linux and productivity tips and like if this helped.
Let us know: What’s your favorite command for managing processes?

👉 Watch now and master managing processes in Linux!

#LinuxTips #ProcessManagement #pkill #killall #ProductivityHacks

(Short, clear, and packed with practical knowledge!)