Monitoring with top
The top command provides a real-time view of system processes, CPU usage, and memory consumption.
Basic Usage
top
Understanding the top Display
Header Section
top - 10:00:00 up 1 day, load average: 0.00, 0.01, 0.05
Tasks: 4 total, 1 running, 3 sleeping
%Cpu(s): 0.1 us, 0.1 sy, 0.0 ni, 99.8 id
MiB Mem : 7900.0 total, 4500.0 free, 2000.0 used
- Load average: System load (1, 5, 15 min)
- Tasks: Process counts by state
- CPU: User, system, idle percentages
- Memory: Total, free, used, cached
Process List
Each line shows a process with:
| Column | Meaning |
|---|---|
| PID | Process ID |
| USER | Owner |
| %CPU | CPU usage |
| %MEM | Memory usage |
| TIME+ | Total CPU time |
| COMMAND | Program name |
Interactive Commands
When top is running:
| Key | Action |
|---|---|
q | Quit |
h | Help |
k | Kill process |
r | Renice (change priority) |
M | Sort by memory |
P | Sort by CPU |
N | Sort by PID |
c | Show full command |
1 | Show per-CPU stats |
Exercise: View System Status
Run top to see system status:
top Options
| Option | Description |
|---|---|
-d N | Update every N seconds |
-n N | Exit after N iterations |
-u user | Show only user's processes |
-p PID | Monitor specific PID |
-b | Batch mode (for scripts) |
top -d 1 # Update every second
top -n 5 # Run 5 times then exit
top -u root # Show root's processes
top -p 1234 # Monitor PID 1234
Understanding Load Average
load average: 0.50, 0.75, 1.00
1min 5min 15min
- < 1.0: System is underutilized
- = 1.0: System is at capacity
- > 1.0: Processes are waiting
For multi-core systems, divide by number of cores.
Memory Information
MiB Mem : 7900.0 total, 4500.0 free, 2000.0 used, 1400.0 buff/cache
- total: Physical RAM
- free: Unused memory
- used: In-use memory
- buff/cache: Disk cache (reclaimable)
Alternatives to top
htop
Enhanced, colorful version:
htop
Features:
- Mouse support
- Color-coded
- Easier process killing
- Tree view
atop
System and process monitor:
atop
Practical Uses
Find Resource Hogs
- Run
top - Press
Mto sort by memory - Press
Pto sort by CPU
Monitor Specific Process
top -p $(pgrep nginx | head -1)
Save top Output
top -b -n 1 > system_report.txt
Key Takeaways
topshows real-time system stats- Interactive: use keys to sort and control
- Watch load average for system health
- Press
qto quit - Consider
htopfor a better interface
التالي · الدرس 31 من 40
Managing Processes (kill)
قراءة 2 دقيقة
أنهيت 30 من 40 درسًا

اسأل Byte عن هذا الدرس
محادثة خاصة حول هذا الدرس. قرأ Byte الدرس كاملًا، ويجيب خلال ثوانٍ، ويُظهر القسم الذي تأتي منه كل إجابة. يمكنك السؤال بأي لغة.
الأسئلة والأجوبة
أسئلة عامة حول هذا الدرس. يجيب AI Tutor فورًا بلغتك، ويراجع فريق FreeAcademy الإجابات، ويمكن لكل المتعلمين قراءتها.

