l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2006 Jun 13 21:23

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] [fwd] [svlug] Question regarding top
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] [fwd] [svlug] Question regarding top

I thought this was pretty cool. 'course, I'm a total newbie with awk. ;)
At the least, it might be useful.


----- Forwarded message from Seth David Schoen -----

Date: Tue, 13 Jun 2006 00:16:28 +0100
From: Seth David Schoen
Subject: Re: [svlug] Question regarding top
To: stripes

stripes writes:

> Hi all,
> I've looked around through /etc/toprc and ~/.toprc, and I can't find any
> way to format the output so it gives memory in MB (instead of kb).
> Is there anyway to do that on top, or do I need to use the free command
> (where I can).

You could modify the source code of top (it's in the procps package).
There doesn't seem to be an existing option in the source code to do

If you don't need to be portable to other Unixes, you might enjoy
something like

awk '{print $1, $2/1024, "MB"}' /proc/meminfo | egrep 'Used|Free'

You can get other values by adding things to your grep command.
You can also put this in a shell script and then call it from "watch"
or add your own loop like

while clear; do
awk '{print $1, $2/1024, "MB"}' /proc/meminfo | egrep 'Used|Free'
sleep 2

There are values that top has that this won't get you because you
would need to calculate FooTotal-FooFree to get FooUsed for certain
values of Foo.  This should be easy to do in awk.  For example:

awk '{values[$1] = $2/1024};
     END {print "SwapUsed:", values["SwapTotal:"] - values["SwapFree:"]}'

Seth David Schoen <schoen loyalty.org> | This is a new focus for the security
     http://www.loyalty.org/~schoen/   | community. The actual user of the PC
     http://vitanuova.loyalty.org/     | [...] is the enemy.
                                       |          -- David Aucsmith, IDF 1999

----- End forwarded message -----
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.