show top 10 most memory hungry process with a simple format of (%mem, pid, short command)

ps -eo pmem,pid,comm --no-headers | sort -k1 -rn | head -10
Pros: the format is very simple, there is no need to show every columns, and full command with args the first column is memory consumption % the second column is pid the third is just the command (without full arguments, most application's arguments are too long) You can decide which application to kill then.
Sample Output
8.2 14730 MATLAB
 5.6  2236 nautilus
 3.1     1 chromium-browse
 2.7  2555 chromium-browse
24.7     1 dropbox
 1.8  2555 chromium-browse
 1.4  2550 chromium-browse
 1.2  2555 chromium-browse
 1.2  2555 chromium-browse
 1.2  2555 chromium-browse

By: dexterhu
2011-03-11 04:51:35

These Might Interest You

  • This is a alternate command I like to use instead of TOP or HTOP to see what are the processes which are taking up the most memory on a system. It shows the username, process ID, CPU usage, Memory usage, thread ID, Number of threads associated with parent process, Resident Set Size, Virtual Memory Size, start time of the process, and command arguments. Then it's sorted by memory and showing the top 10 with head. This of course can be changed to suit you needs. I have a small system which is why Firefox is taking so much resources. Show Sample Output

    watch -n .8 'ps -eaLo uname,pid,pcpu,pmem,lwp,nlwp,rss,vsz,start_time,args --sort -pmem| head -10'
    ubercoo · 2016-05-11 01:05:53 0
  • This command kills all processes with 'SomeCommand' in the process name. There are other more elegant ways to extract the process names from ps but they are hard to remember and not portable across platforms. Use this command with caution as you could accidentally kill other matching processes! xargs is particularly handy in this case because it makes it easy to feed the process IDs to kill and it also ensures that you don't try to feed too many PIDs to kill at once and overflow the command-line buffer. Note that if you are attempting to kill many thousands of runaway processes at once you should use 'kill -9'. Otherwise the system will try to bring each process into memory before killing it and you could run out of memory. Typically when you want to kill many processes at once it is because you are already in a low memory situation so if you don't 'kill -9' you will make things worse

    ps axww | grep SomeCommand | awk '{ print $1 }' | xargs kill
    philiph · 2009-02-28 17:48:51 5
  • Full output in one single git command, no pipes nor other process invocations. Will also work under cmd on Windows, with MSysGit, and can be aliased, simply add [alias] branch-rel = "for-each-ref --sort=-committerdate --format='%1B[32m%(committerdate:iso8601) %1B[34m%(committerdate:relative) %1B[0;m%(refname:short)' refs/heads/" to your .gitconfig file. Show Sample Output

    git for-each-ref --sort=-committerdate --format="%1B[32m%(committerdate:iso8601) %1B[34m%(committerdate:relative) %1B[0;m%(refname:short)" refs/heads/
    mstormo · 2013-03-11 20:48:25 0

  • 0
    echo "Memory:" $(dmidecode --type memory | grep " MB" | awk '{sum += $2; a=sum/1024} END {print a}') "GB"
    bp · 2014-02-18 06:20:34 0

What Others Think

A couple of problems. First, there's a typo. The command uses 'ppid' (parent process id), when you mean 'pid'. Next, you have "head -11 | tail -10". This is ugly and wrong. You've just sorted the list, so the header won't be at the top. head and tail give you lines 2-11 which means I've lost the first entry: the most memory hungry. If you're using the procps version of ps, you can turn off the headers: ps -eo pmem,pid,comm --no-headers | sort -k 1 -r -n | head ps is capable of sorting its output, but I can't get a working example.
flatcap · 379 weeks and 6 days ago
Updated according to flatcap's comments. Thanks very much :-)
dexterhu · 379 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: