Hello guys, In this article, We will discuss how to find the top running processes by memory and CPU usage. Linux is the best operating system for system administrators and developers. Also, when it comes to servers, Linux is the best option due to its stability, security, and lightweight. When running a server, there are many processes running which we can check through the system monitor. But, some processes run in the background which can be displayed by running some commands in a terminal window.
We will discuss the following commands in detail:
- top command
- ps command
- glances command
- htop and atop command
- nmon command
1. top command
The top command gives real-time information about the running processes as well as a summary of system information. It displays uptime, load averages, CPU states, memory usage, and tasks i.e. total, running, sleeping, stopped, and zombie tasks.
It also displays a list of real-time running processes with all the details. To run the top command, execute the following command in a terminal window:
To sort the processes by memory usage, Execute the following command:
top -o %MEM
2. ps command
Unlike top command, which repeatedly displays a list of processes repeatedly, the ps command displays a snapshot of active processes i.e. it does not display the updated information continuously. To run ps command sorted by memory in descending order, Execute the following command:
ps aux --sort -%mem
To sort by memory, Replace the %mem by %cpu in the above command:
ps aux --sort -%cpu
To limit the number of processes using head command, Change the above command as shown:
ps aux --sort -%mem | head-15
To list only specific information about the processes sorted by memory, Execute the following command:
ps -eo pid,%cpu,%mem,cmd --sort -%mem
3. glances command
glances is a monitoring tool that provides maximum information in minimum space. It is written in Python and can also be used for server monitoring and remote monitoring. To install glances, Execute the following command in a terminal window:
sudo apt install glances
Run the glances command:
To monitor the system using a web user interface( web UI), enter the following command:
Right-click on the given address and open it in the browser.
4. htop and atop command
Though it is similar to the glances command, htop command provides you with more information in a colorful display. To install htop command, Run the following command:
sudo apt install htop
Run the htop command:
Similarly, atop command also displays the system information in a more interactive way, It can also store the output in a file. To install atop, Run the following command:
sudo apt install atop
Run the atop command:
5. nmon command
nmon is another monitoring tool that displays all information such as CPU, memory, DIsks, network, kernel, NFS, top processes and resources. To install nmon command, Run the following command:
sudo apt install nmon
Run the nmon command:
Press the appropriate keywords as per your needs. Here, It displays the CPU, memory, Disks, resources, kernel, and network information. To find the top running processes, Press t.
So, We discussed How to find the top running processes by memory and CPU. All the commands almost work similar, only the interface and some information are different. Thank you for reading!