
Monitoring system performance is crucial for maintaining a healthy Linux server. The top and htop commands are two powerful tools for checking real-time system resource usage, including CPU, memory, disk, and process statistics. Here’s how to use both tools to monitor your system performance.
Using top Command
- Launch the
topCommand:
Thetopcommand shows a dynamic, real-time view of the system’s processes, CPU usage, memory usage, and more.top - Understanding
topOutput:
Thetopcommand displays several key metrics:- PID: Process ID
- USER: The user running the process
- PR: Process priority
- %CPU: CPU usage by the process
- %MEM: Memory usage by the process
- COMMAND: The name of the command running
- Sort Processes:
PressShift + Pto sort processes by CPU usage orShift + Mto sort by memory usage. - Kill a Process:
If you want to terminate a process, presskand then enter the PID of the process you wish to kill. - Quit
top:
Pressqto exittop.
Using htop Command
- Install
htop:
Ifhtopis not already installed, you can install it with the following command:sudo apt install htop - Launch the
htopCommand:
To launchhtop, simply type:htop - Understanding
htopOutput:htopprovides a more user-friendly, colorful interface that displays the same information astop, but with additional features:- Process list with CPU and memory usage in bars
- Load average and uptime displayed at the top
- Search and filter options for easier navigation
- Sort Processes:
You can sort processes by CPU or memory usage by clicking on the respective column headers or by pressingF6and selecting the column to sort by. - Manage Processes:
To kill or send signals to a process, select the process and pressF9to choose a signal to send, such asSIGKILL. - Quit
htop:
To exithtop, pressF10orq.
Conclusion
- Use
topfor quick, real-time monitoring of system performance via the command line. - Use
htopfor a more user-friendly, visually appealing interface with additional features like filtering, sorting, and easier process management.
By mastering these tools, you can keep track of your Linux server’s performance and quickly identify any resource-heavy processes or bottlenecks.