[SOLVED] How to show the top processes eating RAM in human readable?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Not sure if you wish to use awk to print records from 4 to NR, or fields from 4 to NF, so here's a sample of each:
Code:
# records:
root@reactor: echo "record1
record2
record3
record4
record5
record6
record7" | awk '{ if (NR>=4) print $0}'
record4
record5
record6
record7
root@reactor:
# fields:
root@reactor: echo "a b c d e f g" | awk -F " " '{ for (x=4;x<=NF;x++) {printf $x" "}; print "\n"}'
d e f g
root@reactor:
I'll leave the conversion to 'human readable' to someone else.
Last edited by GrapefruiTgirl; 08-14-2010 at 11:28 AM.
Reason: changed print to printf - oops!
BTW: I was cautious with the %13.6f part. This leaves room for 6 decimals before the point.
Might be too much, 12.6 is probably better, 11.6 might be pushing it a bit (although: I don't know of any processes that take more then 9999 Mb....). Increased precision is also possible: Increase both parts with 1 (11.6 -> 12.7 -> 13.8).
I used 'sort' and 'head' before processing and I think you should use 'MB' (Megabyte) instead of 'Mb' (Megabit).
Thanks all.
Edited: because of the memory size displays in kilobytes, I edited my above code to hr[1024**2]="GB"; hr[1024]="MB";, it also match with result from free -m:
Nice to see that our hints helped you create your own solution
Two things I would like to mention:
- If it bothers you that there are blank lines between each entry (might be on purpose, don't know) then change the last print statement print ("\n") into print " "
- If a one-liner reaches this size/length it is in general more clear if you make a small script (other up-side: you can re-use it).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.