Linux / Bash
Beginner
1 min read
Viewing and Managing Processes with ps and top
Example
# List all running processes (BSD style)
ps aux
# List processes in forest/tree view
ps auxf
# List processes for current user
ps -u $USER
# Find a specific process
ps aux | grep nginx
pgrep nginx # Returns just the PID(s)
pgrep -l nginx # Returns PID and name
# Show process tree
pstree
pstree -p # Include PIDs
pstree -u # Include usernames
# ---- top ----
top
# Keyboard shortcuts inside top:
# q quit
# M sort by memory
# P sort by CPU (default)
# k kill process (enter PID)
# r renice process
# 1 toggle per-CPU display
# H show threads
# u filter by username
# ---- htop (install: sudo apt install htop) ----
htop
# F5 = tree view | F6 = sort | F9 = kill | F10 = quit
# ---- Process states ----
# R Running
# S Sleeping (interruptible)
# D Sleeping (uninterruptible, usually I/O wait)
# Z Zombie (finished but parent hasn't collected exit status)
# T Stopped / traced
# Watch a command's resource use in real time
watch -n 1 'ps aux --sort=-%cpu | head -15'
Related Resources
Linux / Bash Reference
Complete tag & property list
Linux / Bash How-To Guides
Step-by-step practical guides
Linux / Bash Exercises
Practice what you've learned
More in Linux / Bash