Process Monitoring: Real-Time Watching
Process monitoring watches processes in real-time. See what's happening. Find problems.
Here's the thing: Monitoring processes shows problems. Use it to find what's wrong.
Real-Time Monitoring
top: Basic Monitor
top # Interactive monitor
Navigation:
q= QuitM= Sort by memoryP= Sort by CPU1= Show all CPUsk= Kill process
My take: top is basic. But it works. Use it.
htop: Better Monitor
htop # Better version
My take: Install htop. It's better. More colorful. Easier to use.
watch: Monitor Commands
watch -n 2 'ps aux | grep nginx' # Every 2 seconds
watch -n 5 'systemctl status nginx'
My take: watch monitors commands. Useful for tracking.
Process Trees
pstree: Process Tree
pstree # Process tree
pstree -p # With PIDs
pstree -u # With users
My take: pstree shows process relationships. Useful for understanding.
Process Hierarchy
# Find parent process
ps -o ppid= -p PID
# Find child processes
ps --ppid PID
My take: Understanding hierarchy helps. Find parents. Find children.
Monitoring Specific Processes
Monitor by Name
top -p $(pgrep -d, nginx)
My take: Monitor specific processes. Useful for services.
Monitor by User
top -u username
My take: Monitor user's processes. See what they're doing.
Common Monitoring Patterns
Watch Service
watch -n 2 'systemctl status nginx'
Monitor Resource Usage
htop
# Sort by CPU or memory
Find Resource Hogs
ps aux --sort=-%cpu | head -10 # Top CPU
ps aux --sort=-%mem | head -10 # Top memory
Common Mistakes (I've Made These)
-
Not monitoring: Monitor processes. Find problems early.
-
Only checking CPU: Check CPU, memory, I/O. All matter.
-
Not using htop: Install htop. It's better than top.
-
Ignoring process trees: Trees show relationships. Understand them.
-
Not setting up alerts: Manual monitoring is tedious. Automate it.
Real-World Examples
Monitor Web Server
htop
# Filter for nginx
# Watch CPU and memory
Find Slow Process
ps aux --sort=-%cpu | head -10
Monitor Process Tree
pstree -p nginx
What's Next?
Now that you can monitor processes, you can find problems. Or review Process Management to understand processes better.
Personal note: I used to ignore monitoring. Then processes broke. Now I monitor constantly. It prevents problems. Monitor your processes.