Find the Top Running Processes by Memory and CPU Usage

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:

  1. top command
  2. ps command
  3. glances command
  4. htop and atop command
  5. 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:

top
top-running-processes-1

To sort the processes by memory usage, Execute the following command:

top -o %MEM
top-running-processes-2

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
top-running-processes-3

To sort by memory, Replace the %mem by %cpu in the above command:

ps aux --sort -%cpu
top-running-processes-4

To limit the number of processes using head command, Change the above command as shown:

ps aux --sort -%mem | head-15
top-running-processes-5

To list only specific information about the processes sorted by memory, Execute the following command:

ps -eo pid,%cpu,%mem,cmd --sort -%mem 
top-running-processes-6

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
top-running-processes-7

Run the glances command:

glances
top-running-processes-8

To monitor the system using a web user interface( web UI), enter the following command:

glances -w
top-running-processes-9

Right-click on the given address and open it in the browser.

top-running-processes-10

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
top-running-processes-11

Run the htop command:

htop
top-running-processes-12

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
top-running-processes-13

Run the atop command:

atop
top-running-processes-14

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
top-running-processes-15

Run the nmon command:

nmon
top-running-processes-16

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.

top-running-processes-17

Conclusion

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!