Find processes utilizing high memory in human readable format

ps -eo size,pid,user,command --sort -size |awk '{hr[1024**2]="GB";hr[1024]="MB";for (x=1024**3; x>=1024; x/=1024){if ($1>=x){printf ("%-6.2f %s ", $1/x, hr[x]);break}}}{printf ("%-6s %-10s ", $2, $3)}{for (x=4;x<=NF;x++){printf ("%s ",$x)} print ("\n")}'
Finding high memory usage report in human readable format.
Sample Output
1.49   GB 6457   1001       /opt/google/chrome/chrome --type=renderer --lang=en-US --force-fieldtest=CacheListSize/CacheListSize_14/ConnCountImpact/conn_count_6/ConnnectBackupJobs/ConnectBackupJobsEnabled/DnsImpact/default_enabled_prefetch/DnsParallelism/parallel_default/GlobalSdch/global_enable_sdch/IdleSktToImpact/idle_timeout_10/Instant/HiddenExperimentB/Prefetch/ContentPrefetchPrerender2/PrerenderFromOmnibox/OmniboxPrerenderEnabled/PrerenderFromOmniboxHeuristic/ExactFullAlgorithm/ProxyConnectionImpact/proxy_connections_32/SpdyCwnd/cwnd10/SpdyImpact/npn_with_spdy/WarmSocketImpact/warmest_socket/ --extension-process --enable-print-preview --channel=6390.0xb9b71c60.593461523 

630.18 MB 2488   1001       /usr/lib/thunderbird-3.1.8/thunderbird-bin 

501.08 MB 3426   1001       /usr/lib/firefox-3.6.3/firefox-bin 

272.55 MB 11897  1001       /usr/lib/chromium-browser/chromium-browser 

What Others Think

won't work for me. (GNU bash, version 4.2.24 on Ubuntu 12.04.1 LTS) awk: line 1: syntax error at or near * awk: line 1: syntax error at or near * awk: line 1: extra ')' awk: line 1: syntax error at or near { awk: line 1: syntax error at or near }
olekhy · 310 weeks and 5 days ago
I tried on Ubuntu 11.10 and got same error. Its working for me on Ubuntu 10.04 though the awk version seems same on 10.04 and 11.10 Below command should work for you. ps -eo size,pid,user,command | sort -rn | head -5 | awk '{ hr[1024^2]="GB"; hr[1024]="MB"; for (x=1024^3; x>=1024; x/=1024) { if ($1>=x) { printf ("%-6.2f %s ", $1/x, hr[x]); break } } } { printf ("%-6s %-10s ", $2, $3) } { for ( x=4 ; x<=NF ; x++ ) { printf ("%s ",$x) } print ("\n") }'
rockon · 310 weeks and 4 days ago
I tried on Ubuntu 11.10 and got same error. Its working for me on Ubuntu 10.04 though the awk version seems same on 10.04 and 11.10 Below command should work for you. ps -eo size,pid,user,command | sort -rn | head -5 | awk '{ hr[1024^2]="GB"; hr[1024]="MB"; for (x=1024^3; x>=1024; x/=1024) { if ($1>=x) { printf ("%-6.2f %s ", $1/x, hr[x]); break } } } { printf ("%-6s %-10s ", $2, $3) } { for ( x=4 ; x<=NF ; x++ ) { printf ("%s ",$x) } print ("\n") }'
rockon · 310 weeks and 4 days ago
I tried on Ubuntu 11.10 and got same error. Its working for me on Ubuntu 10.04 though the awk version seems same on 10.04 and 11.10 Below command should work for you. ps -eo size,pid,user,command | sort -rn | head -5 | awk '{ hr[1024^2]="GB"; hr[1024]="MB"; for (x=1024^3; x>=1024; x/=1024) { if ($1>=x) { printf ("%-6.2f %s ", $1/x, hr[x]); break } } } { printf ("%-6s %-10s ", $2, $3) } { for ( x=4 ; x<=NF ; x++ ) { printf ("%s ",$x) } print ("\n") }'
rockon · 310 weeks and 4 days ago
error: can not use output modifiers with user-defined output Usage: ps [options] Try 'ps --help ' or 'ps --help ' for additional help text. For more details see ps(1).
malathion · 310 weeks and 4 days ago
@malathion: what os version?
rockon · 310 weeks and 1 day ago
tnx this one is ok! ps -eo size,pid,user,command | sort -rn | head -5 | awk '{ hr[1024^2]="GB"; hr[1024]="MB"; for (x=1024^3; x>=1024; x/=1024) { if ($1>=x) { printf ("%-6.2f %s ", $1/x, hr[x]); break } } } { printf ("%-6s %-10s ", $2, $3) } { for ( x=4 ; x
olekhy · 310 weeks and 1 day 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?

commandlinefu.com 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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: