Home Linux Commands How to Find Top 10 Running Processes by Memory and CPU Usage

How to Find Top 10 Running Processes by Memory and CPU Usage

Linux is quite popular for its command-line utilities, which not only make any task at hand easier but also saves a lot of time, which is otherwise wasted in graphical UI based utilities.

This is one of the reasons why Linux is a preferred operating system for servers and administrative machines. Combine the knowledge of Linux commands and shell scripting and you have a proper toolkit of system administration at your disposal.

Today we will see how to see the top 10 heaviest memory and CPU resource-consuming processes in Linux using a command-line tool called ps command, which is used to display information about running processes in Linux.

List All Running Processes in Linux

The ps command has a lot of options and arguments available to display output in different formats. However, it can be simply run with the argument ‘aux’ to get a general overview of running processes.

$ ps aux
Overview of Running Processes
Overview of Running Processes

As we can see above, CPU and memory usage are shown in the columns %CPU and %MEM respectively along with other information about the running processes.

Now, we will use the argument '--sort' to sort the output by memory and CPU usage.

The syntax for using the sort argument is:

$ ps aux --sort <column_name>

Similarly, to reverse sort the output, the following can be used:

$ ps aux --sort -<column_name>

Any column from the output can be specified in <column_name>.

List Top 10 Linux Processes by Memory and CPU Usage

Since we want the top 10 processes by memory and CPU usage, we will sort the output by reverse, and put these columns as the column name argument.

Find Top Running Processes by Memory Usage

$ ps aux --sort -%mem
Find Running Processess by Memory Usage
Find Running Processes by Memory Usage

Find Top Running Processes by CPU Usage

$ ps aux --sort -%cpu
Find Running Processess by CPU Usage
Find Running Processes by CPU Usage

Finally, to limit the number of processes shown to 10, we pipe the output to the head command.

$ ps aux --sort -%mem | head -10
$ ps aux --sort -%cpu | head -10
Limit Number of Running Processess
Limit Number of Running Processess

Note that due to some command names being longer and using a new line in the output, ‘head -10’ will consider this new line. You can simply increase the argument to ‘head’ in such cases, for example, to 12 or 14 whichever will bring the number of output processes to 10.

Conclusion

In this article, we saw how to use the ps command to see top resource-consuming processes in Linux. The ps command is a complex command and mastering it comes a long way in properly administering the system and even for using the output in an automation script.

Do refer to the manual page of ps command by running the command:

$ man ps

If you have any questions or feedback, let us know in the comments below.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.