The Invisible Performance Crisis
Your Linux web server has been running perfectly for six months. Suddenly, users start complaining that the website is loading incredibly slowly. You SSH into the server. The terminal gives you a blank command line and no immediate clue as to what is wrong.
Is the database consuming all the RAM? Is a rogue script eating 100% of the CPU? Is a background process quietly filling the hard drive? You need a live, real-time dashboard that shows you exactly what is happening on this machine right now. On a Windows PC, you would open the Task Manager. On Linux, you use the top command.
top is the most essential real-time system monitoring tool in the Linux terminal. It provides a constantly updating, interactive table showing every single process running on the server, ranked by how many system resources each one is consuming.
Launching Top
Simply type the command and press Enter:
top
Unlike most terminal commands that print output and return you to the prompt, top takes over your entire terminal screen. It transforms into a live dashboard that refreshes every three seconds. You will see two main sections: the Header Summary at the top, and the Process Table below.
Reading the Header Summary
The top five lines of the top display contain critical server health data.
Line 1: Uptime and Load Average
This line shows how long the server has been running since its last reboot, how many users are logged in, and the Load Average. The Load Average shows three numbers (e.g., 2.50, 1.80, 0.95), representing the average CPU demand over the last 1 minute, 5 minutes, and 15 minutes.
- If your server has 4 CPU cores and the load average is below 4.00, the server is healthy.
- If the load average is above 4.00, your server is overloaded and tasks are queuing up, waiting for CPU time.
Line 3: CPU Usage Breakdown
This line breaks down how the CPU is spending its time. The two most important numbers are:
- %us (User): The percentage of CPU being used by your actual applications (web servers, databases).
- %id (Idle): The percentage of CPU doing absolutely nothing. If
%idis close to 0%, your CPU is maxed out.
Lines 4-5: Memory (RAM) and Swap
These lines show your total physical RAM, how much is currently used, and how much is free. Critically, look at the Swap line. Swap is emergency overflow memory stored on the hard drive. If the “used” Swap number is very high, your server has run out of RAM and is borrowing from the hard drive, which is catastrophically slow.
Reading the Process Table
Below the header is the main table, listing every running process. The key columns are:
- PID: The Process ID number, a unique identifier you use to kill rogue processes.
- USER: Which user account is running this process.
- %CPU: What percentage of the total CPU this single process is consuming. If a process shows 98%, it is the culprit.
- %MEM: What percentage of the total RAM this process is consuming.
- COMMAND: The name of the actual program (e.g.,
mysqldfor the database,apache2for the web server).
By default, the table is sorted by %CPU, putting the hungriest process at the very top of the list.
Interactive Keyboard Shortcuts
While top is running, you can press keys to interact with it:
- Shift + M: Sort the table by Memory usage instead of CPU.
- Shift + P: Sort back to CPU usage.
- k: Kill a process.
topwill ask you to type the PID of the process you want to terminate. - q: Quit
topand return to your normal terminal.
Conclusion
When a Linux server starts behaving erratically, running top should be your absolute first diagnostic step. Within two seconds, you will have a complete, live picture of CPU load, RAM consumption, and the specific process responsible for the problem.