Find Top Running Processes by Highest Memory and CPU Usage in Linux

I remember once reading that efficient system administrators are lazy people. The reason is not that they’re not doing their job or wasting their time – it is mostly because they have automated a good deal of their routine tasks. Thus, they don’t have to babysit their servers and can use their time to learn new technologies and always stay at the top of their game.

Part of automating your tasks, is learning how to get a script do what you would have to do yourself otherwise. Continually adding commands to your own knowledge base is just as important.

For that reason, in this article we will share a trick to find out, which processes are consuming lots of Memory and CPU utilization in Linux.

Find Linux Processes By RAM and CPU Usage

Find Linux Processes By RAM and CPU Usage

That said, let’s dive in and get started.

Check Top Processes sorted by RAM or CPU Usage in Linux

The following command will show the list of top processes ordered by RAM and CPU use in descendant form (remove the pipeline and head if you want to see the full list):

# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
Sample Output
PID  	PPID 	CMD                      	%MEM 	%CPU
2591	2113 	/usr/lib/firefox/firefox    7.3 	43.5
2549   2520 	/usr/lib/virtualbox/Virtual 3.4  	8.2
2288       1 	/home/gacanepa/.dropbox-dis	1.4	0.3
1889   1543	c:\TeamViewer\TeamViewer.ex	1.0	0.2
2113	1801	/usr/bin/cinnamon		0.9	3.5
2254	2252	python /usr/bin/linuxmint/m	0.3	0.0
2245	1801	nautilus -n			0.3	0.1
1645	1595	/usr/bin/X :0 -audit 0 -aut	0.3	2.5
Find Top Processes By RAM and CPU Usage

Find Top Processes By RAM and CPU Usage

Brief explanation of above options used in above command.

The -o (or –format) option of ps allows you to specify the output format. A favorite of mine is to show the processes’ PIDs (pid), PPIDs (pid), the name of the executable file associated with the process (cmd), and the RAM and CPU utilization (%mem and %cpu, respectively).

Additionally, I use --sort to sort by either %mem or %cpu. By default, the output will be sorted in ascendant form, but personally I prefer to reverse that order by adding a minus sign in front of the sort criteria.

To add other fields to the output, or change the sort criteria, refer to the OUTPUT FORMAT CONTROL section in the man page of ps command.

Don’t Miss: Find Top 15 Processes by Memory Usage with ‘top’ in Batch Mode

Don’t Miss: Find top 10 Directories Disk Size in Linux

Summary

Monitoring process is one of the numerous tasks of a Linux server system administrator, in this tip, we looked at how you list processes on your system and sort them according to RAM and CPU use in descendant form using the ps utility.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

12 Responses

  1. Sai krishna says:

    Getting below.

    /root% ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
    ps: unrecognized option `--sort=-%mem'
    BusyBox v1.21.1 (2014-02-13 02:54:33 CET) multi-call binary.
    
    Usage: ps [-o COL1,COL2=HEADER]
    
    Show list of processes
    -o COL1,COL2=HEADER	Select columns for display
    
  2. Salvador Avila says:

    Great!! how can I add the user?, I was trying by -u, or -U but did not work..

  3. JimM says:

    Super info! I just tried it on Mint 18.3 Mate and you don’t need ‘sudo’. Normal user is fine.

  4. Prem says:

    If your server has 5 CPU, then how to interpret your result? 43.5% for ALL 5 CPU, or 43.5% or just one CPU?

  5. linda says:

    I am new for UNIX can you help me for this question please?

    The pointy-haired manager’s good friend in marketing called him and said the system is way to slow today. Mr. Pointy-hair wants you to send him a file ‘right now’ with the top ten CPU using processes.

    Work out a command structure that can be issued to find running processes, sort them by CPU utilization, and return only the top ten CPU utilizing processes to a file called, top_cpu_out.txt.

  6. Shndo says:

    Hi, great information. Thank you!

    How we can add total Time of each process to the list?

    Thank you!

  7. Prasad says:

    Really Cool

  8. Hugo says:

    Hello,
    do you know a similar command for centOS?

  9. Usman Nasir says:

    Was looking for something like this, really liked the -o flag though.

Leave a Reply to Sai krishna Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.