Linux CLI 21 🐧 view and terminate processes
Processes are the running applications that consume system resources like CPU and memory. Every process has a unique PID (Process ID), and can be viewed with ps or top, and terminated with kill or pkill.
What Are Processes?
A process is an instance of a running program. Every command you run creates a process.
Key concepts:
| Term | Description |
|---|---|
| Process | A running program consuming resources |
| PID | Process ID — a unique number assigned at creation |
| Parent process | The process that started another process |
| Child process | A process started by another process |
| Resources | CPU, memory, disk I/O, network, etc. |
Key point: A PID is assigned when the process is created and stays the same throughout its life.
Visual — parent and child processes:
┌──────────────────┐
│ bash (PID 100) │ ← parent
└────────┬─────────┘
│ starts
┌────┴────┐
▼ ▼
┌────────┐ ┌────────┐
│ls(PID │ │vim(PID │ ← children
│ 101) │ │ 102) │
└────────┘ └────────┘
Commands Overview
| Command | Purpose |
|---|---|
ps | Snapshot of running processes |
top | Real-time process viewer |
htop | Interactive process viewer (better) |
kill | Terminate a process by PID |
pkill | Terminate processes by name |
The ps Command
Process Status — displays information about running processes.
ps aux
ps -u kronos
ps --pid=31009
| Command | Description |
|---|---|
ps aux | All processes with detailed info |
ps -u kronos | Processes owned by kronos |
ps --pid=31009 | Info about a specific process |
ps -ef | Alternative format (System V) |
ps -e | All processes, simple format |
ps aux | grep nginx | Filter by name |
Understanding ps aux Output
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 168336 13212 ? Ss Jan14 0:03 /sbin/init
root 512 0.0 0.2 41208 8108 ? Ss Jan14 0:00 /usr/sbin/sshd
kronos 1234 0.5 1.2 512345 45678 pts/0 S+ 10:30 0:02 vim notes.txt
kronos 5678 2.3 5.6 876543 98765 pts/1 R+ 10:35 0:15 firefox
| Column | Meaning |
|---|---|
| USER | User who owns the process |
| PID | Process ID |
| %CPU | CPU usage percentage |
| %MEM | Memory usage percentage |
| VSZ | Virtual memory size (KB) |
| RSS | Resident Set Size — physical memory (KB) |
| TTY | Terminal the process is attached to |
| STAT | Process state |
| START | Start time/date |
| TIME | Total CPU time used |
| COMMAND | Command that started the process |
The STAT Column — Process States
| Symbol | Meaning |
|---|---|
R | Running — actively using CPU |
S | Sleeping — waiting for an event |
D | Disk sleep — uninterruptible wait for I/O |
Z | Zombie — finished but not reaped by parent |
T | Stopped — paused (Ctrl+Z) |
I | Idle — idle kernel thread |
< | High priority |
N | Low priority |
s | Session leader |
+ | Foreground process group |
Common combinations:
Ss → Sleeping, session leader
R+ → Running, foreground
S+ → Sleeping, foreground
Z → Zombie
Filtering ps Output
By user:
$ ps -u kronos
PID TTY TIME CMD
1234 pts/0 00:00:02 bash
5678 pts/0 00:00:00 vim
By PID:
$ ps --pid=1234
PID TTY TIME CMD
1234 pts/0 00:00:02 vim
By name (with grep):
$ ps aux | grep nginx
root 812 0.0 0.1 ... nginx: master process
www-data 813 0.0 0.1 ... nginx: worker process
Just the name and PID:
$ ps -eo pid,comm
PID COMMAND
1 systemd
512 sshd
1234 bash
The top Command
A real-time process viewer that updates continuously.
top
Sample output:
top - 10:35:22 up 2 days, 3:15, 2 users, load average: 0.52, 0.48, 0.45
Tasks: 245 total, 1 running, 244 sleeping, 0 stopped, 0 zombie
%Cpu(s): 5.2 us, 1.1 sy, 0.0 ni, 93.5 id, 0.2 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 16384.0 total, 8124.3 free, 5123.4 used, 3136.3 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 10214.0 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
5678 kronos 20 0 876543 98765 12345 R 15.3 5.6 1:32.45 firefox
1234 kronos 20 0 512345 45678 5678 S 2.5 1.2 0:15.20 vim
1 root 20 0 168336 13212 8765 S 0.0 0.1 0:03.12 systemd
Understanding the header:
- load average — system load over 1, 5, 15 minutes
- Tasks — total processes by state
- %Cpu(s) — CPU breakdown (us=user, sy=system, id=idle, wa=wait)
- MiB Mem — memory usage
- MiB Swap — swap usage
Interactive Shortcuts in top
| Key | Action |
|---|---|
z | Toggle colors |
1 | Toggle between single and per-CPU view |
f | Select which fields to show |
s | Set update interval (seconds) |
h | Show help |
q | Quit top |
k | Kill a process (prompts for PID) |
M | Sort by memory usage |
P | Sort by CPU usage |
T | Sort by time |
u | Filter by user |
Examples in action:
$ top
# Press z → colors on/off
# Press 1 → see each CPU core
# Press f → choose columns (add PIDs, user, etc.)
# Press s → set refresh to 2 seconds
# Press M → sort by memory
# Press q → exit
The kill Command
Sends a signal to a process by PID — usually to terminate it.
kill -9 PID
kill -15 PID
kill -l
| Command | Description |
|---|---|
kill PID | Sends SIGTERM (default, signal 15) |
kill -9 PID | Force kill (SIGKILL) |
kill -15 PID | Normal terminate (SIGTERM) |
kill -l | List all available signals |
kill -SIGKILL PID | Same as -9 (named signal) |
kill -SIGTERM PID | Same as -15 |
kill -1 PID | SIGHUP — reload configuration |
kill -2 PID | SIGINT — same as Ctrl+C |
Common Signals
| Number | Name | Description |
|---|---|---|
1 | SIGHUP | Hangup / reload config |
2 | SIGINT | Interrupt (Ctrl+C) |
9 | SIGKILL | Force kill (cannot be caught) |
15 | SIGTERM | Normal termination (default) |
18 | SIGCONT | Continue stopped process |
19 | SIGSTOP | Stop process (cannot be caught) |
20 | SIGTSTP | Stop process (Ctrl+Z) |
Examples
Normal termination (graceful):
$ kill -15 5678
# or
$ kill 5678
# Process gets a chance to clean up
Force kill (immediate):
$ kill -9 5678
# Process is terminated immediately — no cleanup
Using signal names:
$ kill -SIGTERM 5678
$ kill -SIGKILL 5678
Reload config (for daemons):
$ kill -SIGHUP 812
# Many daemons reload their config on SIGHUP
List all signals:
$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
13) SIGPIPE 14) SIGALRM 15) SIGTERM ...
SIGTERM vs SIGKILL
| Aspect | SIGTERM (15) | SIGKILL (9) |
|---|---|---|
| Cleanup | ✅ Process can clean up | ❌ No cleanup |
| Can be caught? | ✅ Yes | ❌ No |
| Use case | Normal termination | Forced termination |
| Preferred? | ✅ Try this first | ⚠️ Last resort |
Best practice:
# Try graceful shutdown first
$ kill -15 5678
# Wait a few seconds
# If still running, force kill
$ kill -9 5678
The pkill Command
Process KILL — sends signals to processes by name (or other criteria).
pkill -1 name
pkill -9 name
pkill -15 name
pkill -9 -u user name
| Command | Description |
|---|---|
pkill -1 name | Reload a process (SIGHUP) |
pkill -9 name | Force kill (SIGKILL) |
pkill -15 name | Terminate normally (SIGTERM) |
pkill -9 -u user name | Kill by name for specific user |
Examples
Kill by name:
$ pkill firefox
# Kills all processes named "firefox"
Force kill:
$ pkill -9 chrome
Reload a daemon:
$ pkill -1 nginx
# Reloads nginx configuration
Kill processes for a specific user:
$ pkill -9 -u alice firefox
# Only kills firefox processes owned by alice
Kill by pattern:
$ pkill -f "python.*script"
# -f matches against full command line
Common pkill Options
| Option | Description |
|---|---|
-u user | Match by user |
-f | Match against full command line |
-x | Exact name match |
-n | Newest process |
-o | Oldest process |
-c | Count matching processes |
-e | Echo what’s killed |
-l | List signal names |
Complete Example Session
# ============================================
# PART 1: VIEWING PROCESSES
# ============================================
# All processes with detail
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 168336 13212 ? Ss Jan14 0:03 /sbin/init
root 512 0.0 0.2 41208 8108 ? Ss Jan14 0:00 sshd
kronos 1234 0.5 1.2 512345 45678 pts/0 S+ 10:30 0:02 vim
# Filter by user
$ ps -u kronos
PID TTY TIME CMD
1234 pts/0 00:00:02 vim
5678 pts/0 00:00:00 bash
# Specific PID
$ ps --pid=1234
PID TTY TIME CMD
1234 pts/0 00:00:02 vim
# Filter by name
$ ps aux | grep firefox
kronos 5678 2.3 5.6 ... firefox
# ============================================
# PART 2: TOP COMMAND
# ============================================
$ top
# Press z → colors
# Press 1 → per-CPU view
# Press M → sort by memory
# Press P → sort by CPU
# Press u → filter by user
# Press k → kill a process
# Press h → help
# Press q → quit
# ============================================
# PART 3: KILL COMMAND
# ============================================
# Find the PID
$ ps aux | grep firefox
kronos 5678 2.3 5.6 ... firefox
# Try graceful termination
$ kill -15 5678
# If still running, force kill
$ kill -9 5678
# Using signal names
$ kill -SIGTERM 5678
$ kill -SIGKILL 5678
# Reload a daemon
$ sudo kill -SIGHUP 812
# List all signals
$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT ...
# ============================================
# PART 4: PKILL COMMAND
# ============================================
# Kill by name
$ pkill firefox
# Force kill all chrome processes
$ pkill -9 chrome
# Reload nginx
$ sudo pkill -1 nginx
# Kill firefox for user alice only
$ pkill -9 -u alice firefox
# Match full command line
$ pkill -f "python.*script.py"
# Count matches without killing
$ pkill -c firefox
5
# See what would be killed
$ pkill -e firefox
firefox killed (pid 5678)
firefox killed (pid 5679)
# ============================================
# PART 5: PRACTICAL SCENARIOS
# ============================================
# Scenario 1: App is frozen
$ ps aux | grep firefox
kronos 5678 99.0 5.6 ... firefox
$ kill -9 5678
# ✅ Force killed the frozen process
# Scenario 2: Kill all by name
$ pkill -9 chrome
# Kills all chrome processes at once
# Scenario 3: Restart a service gracefully
$ sudo pkill -1 nginx
# Nginx reloads config without dropping connections
# Scenario 4: Find and kill a runaway Python script
$ ps aux | grep python
kronos 9100 95.0 10.0 ... python data_process.py
$ kill -15 9100
# Give it a chance to save state
# If ignored:
$ kill -9 9100
# Scenario 5: Filter processes by user
$ ps -u alice
$ ps aux | grep "^alice"
# Scenario 6: Real-time monitoring
$ top
# Watch CPU, memory, and process list update
# Scenario 7: Kill a process by pattern
$ pkill -f "java -jar myapp.jar"
# Kills the specific Java app
# Scenario 8: Zombie process
$ ps aux | grep defunct
user 1234 0.0 0.0 ... [python] <defunct>
# Zombie — needs to be reaped by parent process
Quick Reference
ps Options
| Option | Description |
|---|---|
aux | All processes, detailed |
-ef | All processes (Unix style) |
-u user | Filter by user |
--pid=PID | Specific PID |
-e | All processes |
Process States (STAT)
| Symbol | Meaning |
|---|---|
R | Running |
S | Sleeping |
D | Disk sleep |
Z | Zombie |
T | Stopped |
I | Idle |
< | High priority |
top Shortcuts
| Key | Action |
|---|---|
z | Colors |
1 | Per-CPU view |
f | Fields |
s | Update interval |
h | Help |
q | Quit |
k | Kill process |
M / P | Sort by mem / CPU |
Common Signals
| Number | Name | Purpose |
|---|---|---|
1 | SIGHUP | Reload config |
2 | SIGINT | Interrupt (Ctrl+C) |
9 | SIGKILL | Force kill |
15 | SIGTERM | Normal terminate |
Best Practices
✅ Do This:
# Try SIGTERM first, then SIGKILL
kill -15 PID
sleep 3
kill -9 PID
# Use ps or top to find the PID
ps aux | grep firefox
# Then kill the specific PID
# Use pkill by name for convenience
pkill firefox
# Reload daemons with SIGHUP
sudo pkill -1 nginx
# Filter by user to avoid killing wrong processes
pkill -u alice firefox
# Check what would be killed before doing it
pkill -c firefox # Count matches
❌ Don’t Do This:
# Don't jump straight to -9
kill -9 PID # ❌ Process can't clean up!
kill -15 PID # ✅ Try this first
# Don't kill PID 1
kill -9 1 # ❌ Kills init — system crash!
# Don't pkill with common names
pkill -9 bash # ❌ Kills your own shell!
pkill -9 python # ⚠️ Kills ALL Python processes
# Don't use kill on your own shell
kill -9 $$ # ❌ Kills your current shell
# Don't ignore what ps tells you
ps aux | grep chrome
# Before killing, verify it's really chrome!
Common Pitfalls
| Pitfall | Problem | Solution |
|---|---|---|
kill -9 first | No cleanup | Try -15 first |
| Killing PID 1 | System crash | Never touch PID 1 |
pkill common name | Kills unrelated processes | Use -u or -f |
| Wrong PID | Kills wrong process | Verify with ps first |
| Zombie won’t die | Parent hasn’t reaped | Restart parent |
kill on systemd service | Doesn’t restart | Use systemctl stop |
Real-World Examples
1. Kill a Frozen App
# Find the frozen process
$ ps aux | grep firefox
kronos 5678 99.0 ... firefox
# Try graceful shutdown
$ kill -15 5678
# Force kill if needed
$ kill -9 5678
2. Stop All Chrome Processes
$ pkill chrome
$ pkill -9 chrome
3. Reload Nginx Config
$ sudo pkill -1 nginx
# Nginx re-reads its config without dropping connections
4. Kill Runaway Python Script
$ ps aux | grep python
kronos 9100 95.0 ... python process.py
$ kill -15 9100
$ kill -9 9100
5. Find Top CPU Consumers
$ ps aux --sort=-%cpu | head -10
# Top 10 CPU hogs
6. Find Top Memory Consumers
$ ps aux --sort=-%mem | head -10
# Top 10 memory hogs
7. Kill Process for Specific User
$ sudo pkill -9 -u alice firefox
8. Live Monitoring
$ top
# Press M → sort by memory
# Press P → sort by CPU
# Press u → filter by user
# Press k → kill a process
9. Find Processes by Terminal
$ ps -t pts/0
# All processes on terminal pts/0
10. Kill Interactive
# From top:
$ top
# Press k
# Enter PID: 5678
# Enter signal: 15
# ✅ Killed
Visual: Process Lifecycle
Creation ────→ Running ────→ Sleeping ────→ Terminated
│ ▲ │ │
│ │ │ │
└───┘ └──────────────┘
(CPU use) (waiting for event)
Signals:
SIGTERM (15) → "Please stop" (can clean up)
SIGKILL (9) → "STOP NOW!" (cannot be caught)
SIGHUP (1) → "Reload config" (for daemons)
SIGSTOP (19) → "Pause" (cannot be caught)
SIGCONT (18) → "Resume"
Summary
| Command | Purpose | Example |
|---|---|---|
ps aux | View all processes | ps aux |
ps -u user | Processes by user | ps -u kronos |
top | Real-time viewer | top |
kill -15 PID | Graceful terminate | kill -15 5678 |
kill -9 PID | Force kill | kill -9 5678 |
pkill name | Kill by name | pkill firefox |
kill -l | List signals | kill -l |
Key takeaways:
- Processes are running programs — each has a unique PID
psgives a snapshot — useauxfor detailtopshows real-time — pressqto quit,M/Pto sortkill -15is the graceful option — try this firstkill -9is the nuclear option — last resortpkillkills by name — convenient but be specific (-u,-f)- Signals are communication — SIGHUP reloads, SIGTERM terminates, SIGKILL forces
- NEVER kill PID 1 — it’s the init system
- Verify the PID before killing — a wrong PID can kill something important
Remember: The process viewer ps and top are your eyes into what’s running. kill and pkill are your hands for stopping it. The golden rule: always try SIGTERM (15) first — it gives the process a chance to save state and clean up. Only use SIGKILL (9) when the process is truly stuck. And never kill a process you don’t understand — especially not PID 1!
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!