[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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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 12:28 PM.
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.