top
Overview
The top
command provides a dynamic real-time view of running processes. It shows system summary information and a list of processes or threads currently managed by the Linux kernel.
Syntax
top [options]
Common Options
Option | Description |
---|---|
-b |
Batch mode output |
-n num |
Number of iterations |
-d delay |
Screen update interval |
-p pid |
Monitor specific PIDs |
-u user |
Show specific user’s processes |
-H |
Show threads |
-i |
Ignore idle processes |
-c |
Show command line |
-w |
Wide output |
Key Use Cases
- System monitoring
- Process tracking
- Resource usage analysis
- Performance troubleshooting
- Memory management
Examples with Explanations
Example 1: Basic Usage
top
Show dynamic process view
Example 2: Specific User
top -u username
Show user’s processes
Example 3: Specific Process
top -p 1234
Monitor specific PID
Interactive Commands
Key | Action |
---|---|
h | Help |
q | Quit |
k | Kill process |
r | Renice process |
f | Fields management |
o | Sort field |
M | Sort by memory |
P | Sort by CPU |
T | Sort by time |
W | Save settings |
Understanding Output
Header sections: 1. System uptime and load 2. Tasks summary 3. CPU states 4. Memory usage 5. Swap usage 6. Process list
Common Usage Patterns
Monitor system load:
top -d 5
Save output:
top -b -n 1 > top_output.txt
Track specific processes:
top -p $(pgrep firefox)
Performance Analysis
- Real-time monitoring
- Resource overhead
- Update frequency impact
- Process count effect
- Memory usage
Additional Resources
Best Practices
- Regular monitoring
- Custom configurations
- Alert thresholds
- Resource tracking
- Performance baselines