top
Overview
The top
command provides a dynamic real-time view of running processes. It shows system summary information and a list of processes currently being managed by the Linux kernel.
Syntax
top [options]
Common Options
Option | Description |
---|---|
-b |
Batch mode |
-n num |
Number of iterations |
-p pid |
Monitor PID |
-u user |
User processes |
-H |
Show threads |
-i |
Idle processes |
-c |
Command line |
-w |
Output width |
-d delay |
Update delay |
-o field |
Sort field |
-U user |
User filter |
-E scale |
Memory scale |
Interactive Commands
Key | Action |
---|---|
h |
Help |
q |
Quit |
k |
Kill process |
r |
Renice process |
f |
Fields management |
o |
Sort field |
u |
User filter |
M |
Sort by memory |
P |
Sort by CPU |
T |
Sort by time |
W |
Write config |
Key Use Cases
- System monitoring
- Resource tracking
- Process management
- Performance analysis
- Troubleshooting
Examples with Explanations
Example 1: Basic Usage
top
Show system status
Example 2: Specific User
top -u username
Show user processes
Example 3: Batch Mode
top -b -n 1
Single iteration output
Common Usage Patterns
Monitor PID:
top -p 1234
Sort by memory:
top -o %MEM
Update faster:
top -d 0.5
Header Information
- System uptime
- Load averages
- CPU states
- Memory usage
- Swap usage
Additional Resources
Best Practices
- Regular monitoring
- Set refresh rate
- Use filters
- Check trends
- Document issues
Security Considerations
- Process visibility
- User permissions
- Resource impact
- Signal handling
- Configuration
Troubleshooting
- High CPU use
- Memory leaks
- Process states
- System load
- Performance issues
Output Fields
- PID
- USER
- PR/NI
- VIRT/RES/SHR
- S (Status)