Linux Top Command: The Ultimate Guide to Monitor Linux Processes and System Performance
If your Linux server is slowing down, there’s one command you should run first: top. When managing Linux servers and applications, keeping track of system performance is crucial for maintaining optimal operations. The Linux top command stands as one of the most essential tools in every system administrator’s toolkit, providing real-time insights into CPU usage, memory consumption, and running processes.
Whether you’re troubleshooting performance issues, identifying resource-hungry applications, or simply monitoring your system’s health, mastering the Linux top command will significantly enhance your DevOps capabilities. This comprehensive guide covers everything from basic usage to advanced techniques that will help you become more efficient in your daily operations.
What is the Linux Top Command?
The Linux top command is a built-in system monitoring utility that displays real-time information about running processes and overall system performance. It provides a dynamic view of your system’s current state, updating every few seconds to show the latest CPU usage, memory utilization, and process activity.
While ps provides a snapshot, top gives you a real-time, continuously updating view, making it indispensable for live diagnostics. The command has been a cornerstone of Linux system administration since the early days of Unix-like operating systems.
Understanding the Linux Top Command Interface
When you run the basic top command, you’ll see a screen divided into two main sections:
System Summary (Top Section)
The upper portion displays overall system statistics:
top - 14:23:15 up 5 days, 2:45, 3 users, load average: 0.45, 0.32, 0.28
Tasks: 247 total, 1 running, 246 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.3 us, 0.7 sy, 0.0 ni, 96.8 id, 0.2 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 15872.4 total, 8234.2 free, 3456.7 used, 4181.5 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 11987.3 avail Mem
Key metrics explained:
- Load average: System load over 1, 5, and 15-minute intervals
- Tasks: Total number of processes and their states
- CPU usage: Breakdown of CPU time allocation
- Memory: Physical RAM and swap space utilization
Process List (Bottom Section)
The lower section shows individual processes with columns like:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 apache 20 0 145678 45231 12345 S 2.3 0.3 0:45.67 httpd
5678 mysql 20 0 987654 234567 56789 S 1.7 1.5 12:34.89 mysqld
Key column explanations:
| Column | Description | Key Insight |
|---|---|---|
| PID | Process ID | The unique number used to manage the process |
| %CPU | CPU Usage | The percentage of a single CPU core this process is using. Can exceed 100% on multi-core systems |
| %MEM | Memory Usage | Percentage of physical RAM the process’s resident memory (RES) uses |
| RES | Resident Memory | The actual physical RAM currently held by the process (in KiB or MiB) |
| VIRT | Virtual Memory | The total virtual memory used by the process (code, data, shared libraries + swapped pages) |
| TIME+ | CPU Time | Total CPU time the process has consumed since it started |
| COMMAND | Process Name | The command or program name that started this process |
Basic Linux Top Command Usage
Starting Top
The simplest way to start monitoring Linux processes is:
top
This launches top with default settings, updating every 3 seconds.
Essential Navigation
Once top is running, you can use these basic controls:
- q: Quit top
- Space: Immediately refresh the display
- h: Display help screen
- 1: Toggle between single CPU view and individual core breakdown
Customizing Refresh Rate
To change how frequently top updates:
# Update every 1 second
top -d 1
# Update every 5 seconds
top -d 5
Advanced Top Command Options and Shortcuts
Sorting Processes
The Linux top command offers several sorting options to help you identify problematic processes:
Sort by CPU usage (default):
top
# Then press 'P' to sort by CPU
Sort by memory usage:
top
# Then press 'M' to sort by memory
Sort by process time:
top
# Then press 'T' to sort by cumulative time
Advanced Command-Line Options
Monitor specific processes:
# Monitor only processes owned by a specific user
top -u username
# Monitor specific process IDs
top -p 1234,5678,9012
Batch mode for logging:
# Run in batch mode (non-interactive)
top -b -n 1 > system_snapshot.txt
# Continuous logging
top -b -d 5 >> system_monitoring.log
Powerful Interactive Commands
While top is running, these shortcuts provide advanced functionality:
Process filtering:
- o: Filter processes by any criteria
- u: Filter by username
- k: Kill a process (requires PID)
Display customization:
- f: Choose which columns to display
- F: Select sort column
- R: Reverse sort order
- c: Toggle command line display
Real-World Linux Process Monitoring Scenarios
Scenario 1: Identifying High CPU Usage
When your server is experiencing high load, use these top command examples:
# Sort by CPU and show only top 10 processes
top -o %CPU -n 1 | head -15
# Continuous clean view of top CPU processes (alternative to full top interface)
watch -n 1 "top -o %CPU -n 1 | head -15"
# Monitor CPU usage continuously with 1-second updates
top -d 1
In the interactive mode:
- Press P to sort by CPU usage
- Press 1 to see individual CPU cores
- Identify processes consuming excessive resources
Scenario 2: Memory Usage Linux Monitoring
To track memory-intensive applications:
# Sort by memory usage
top -o %MEM
# Show individual threads instead of processes
top -H
Interactive monitoring:
- Press M to sort by memory usage
- Look for processes with high RES (resident memory)
- Check %MEM column for percentage usage
- Pro tip: A process with high VIRT but low RES is using allocated but not actively used memory, which is less concerning than high RES
Scenario 3: User-Specific Process Monitoring
Monitor processes owned by specific users:
# Monitor Apache processes
top -u apache
# Monitor database processes
top -u mysql
# Monitor multiple users
top -U "apache,mysql,nginx"
Scenario 4: Killing Processes from Top
When you need to terminate problematic processes:
- Run
top - Note the PID of the problematic process
- Press k
- Enter the PID when prompted
- Choose signal (15 for SIGTERM, 9 for SIGKILL)
Linux Top Command Cheat Sheet
| Shortcut | Function | Description |
|---|---|---|
| q | Quit | Exit top command |
| h | Help | Display help screen |
| Space | Refresh | Immediately update display |
| 1 | CPU Toggle | Switch between summary and per-core view |
| P | Sort CPU | Sort processes by CPU usage |
| M | Sort Memory | Sort processes by memory usage |
| T | Sort Time | Sort by cumulative CPU time |
| k | Kill | Kill a process (requires PID) |
| u | User Filter | Filter processes by username |
| o | Field Filter | Filter by any field criteria |
| f | Field Select | Choose which columns to display |
| F | Sort Column | Select sort field |
| R | Reverse Sort | Reverse current sort order |
| c | Command Toggle | Show/hide full command line |
| i | Idle Toggle | Hide/show idle processes |
| V | Forest View | Show process hierarchy |
| W | Write Config | Save current configuration |
Frequently Asked Questions
What is top command in Linux?
The Linux top command is a real-time system monitoring tool that displays running processes, CPU usage, memory consumption, and other vital system statistics. It provides a dynamic view of system performance that updates continuously, making it essential for system administrators and DevOps professionals.
How to sort by memory in top?
To sort processes by memory usage in top:
1. Run the top command
2. Press M to sort by memory usage (%MEM column)
3. Alternatively, use top -o %MEM to start with memory sorting
How do I exit the top command?
To exit the top command, simply press q (quit). This will return you to the command prompt immediately.
How to monitor specific user processes in top?
Use the -u option followed by the username:
top -u username
Or while top is running, press u and enter the username when prompted.
Can I run top in batch mode for scripting?
Yes, use the -b flag for batch mode:
top -b -n 1 # Single snapshot
top -b -n 5 -d 2 # 5 iterations with 2-second delays
How to kill a process from within top?
1. Press k while top is running
2. Enter the PID of the process you want to kill
3. Enter the signal number (15 for graceful termination, 9 for force kill)
Important: Always try SIGTERM (15) first, as it allows the process to shut down gracefully. Only use SIGKILL (9) if the process ignores SIGTERM, as it forces an immediate termination without cleanup.
What does load average mean in top?
Load average shows the average number of processes waiting for CPU time over 1, 5, and 15-minute periods. Values below your CPU core count indicate good performance, while higher values suggest system stress. For example, a load average of 3.50 on a 4-core CPU means 3.5 processes were, on average, utilizing or waiting for the CPU. A value consistently higher than the number of cores indicates a CPU bottleneck.
How to save top configuration permanently?
While in top, press W to write the current configuration to your home directory. This saves your preferred settings for future top sessions.
Advanced DevOps Tips and Best Practices
1. Automated Monitoring Scripts
Create monitoring scripts using top for alerting:
#!/bin/bash
# Check if any process uses more than 80% CPU
CPU_THRESHOLD=80
HIGH_CPU=$(top -b -n 1 | awk -v threshold=$CPU_THRESHOLD '$9 > threshold {print $1, $9, $12}')
if [ ! -z "$HIGH_CPU" ]; then
echo "High CPU usage detected: $HIGH_CPU" | mail -s "CPU Alert" admin@company.com
fi
2. Performance Baseline Creation
Use top in batch mode to create performance baselines:
# Create daily snapshots
top -b -n 1 > /var/log/performance/baseline_$(date +%Y%m%d).log
# Monitor during peak hours
top -b -n 60 -d 60 > /var/log/performance/peak_hours_$(date +%Y%m%d_%H).log
Pro tip: Consider using logrotate to manage these files and prevent them from consuming too much disk space.
3. Container Environment Monitoring
When working with containers, remember that top shows host processes. For container-specific monitoring:
# Monitor specific container processes
docker exec container_name top
# Or use top with process filtering
top -p $(docker inspect --format '{{.State.Pid}}' container_name)
Note: In modern Kubernetes environments, you’d typically use kubectl top pod instead of logging into nodes, but knowing top is crucial for deep node-level debugging when container orchestration tools aren’t sufficient.
4. Integration with Monitoring Systems
Combine top with monitoring tools:
# Extract metrics for external monitoring
top -b -n 1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1 > cpu_usage.metric
top -b -n 1 | grep "MiB Mem" | awk '{print $4}' | cut -d',' -f1 > memory_used.metric

Conclusion
The Linux top command remains an indispensable tool for effective system monitoring and process management. From basic CPU usage monitoring to advanced process filtering and real-time troubleshooting, mastering top significantly enhances your ability to maintain healthy, performant systems.
By implementing the techniques covered in this guide, you’ll be better equipped to identify performance bottlenecks, troubleshoot system issues, and maintain optimal server performance. Remember to combine top with other monitoring tools and automation scripts to create a comprehensive monitoring strategy for your DevOps environment.
The key to effective Linux process monitoring lies in understanding not just how to use these commands, but when and why to apply specific techniques. Regular practice with different scenarios will help you develop the intuition needed to quickly identify and resolve system performance issues.
Whether you’re managing a single server or a complex distributed infrastructure, the Linux top command provides the foundational monitoring capabilities that every DevOps professional needs in their toolkit.
