Memory Accounting, JDKs [was: Re: [Techtalk] Java on Linux]

Laurel Fan laurel at sdf.lonestar.org
Thu Jan 10 18:15:35 EST 2002


On Thu, Jan 10, 2002 at 04:37:55PM -0800, Nicole Zimmerman wrote:
> /proc/meminfo is where I am getting my system memory stats from -- so far
> the most reliable source :o)

Incidentally, /proc/meminfo is probably where ps and top get their
system memory stats from as well.

If you do an strace[1] on ps and top, you can see them opening
/proc/meminfo.

[1] strace runs a command and the prints out every syscall it makes.
It's useful for just poking around at stuff and see how things work.
For example, to verify my guess that ps looked at /proc/meminfo, I
did:

strace ps |& grep meminfo 

and got:
open("/proc/meminfo", O_RDONLY)         = 5
read(7, "grep\0meminfo\0", 2047)        = 13

The |& means redirect both stderr (the STandarD place to put ERRors,
where strace puts its output) and stdout (the STandarD place to put
OUTput, where ps, the command we're stracing puts its output).  This
will work in csh, tcsh, and zsh.  For bash and ksh try "strace ps 2>&1
| grep meminfo".  If you're using some other shell, you probably don't
need me to tell you how to do it.

First line means that it's calling the open syscall[2], and telling it to
open the /proc/meminfo file.  The O_RDONLY means that it only wants to
read the file, not write it.

Second line is sort of interesting, it's reading in information about
the grep command I just typed.

I use strace all the time; just recently I forgot what the syscall for
reading directory entries was (it's getdents, btw), and figured it out
by straceing ls.

[2] All (well, most. should be all) syscalls have manpages, and are in
section 2.  If you look at the manpage for the open syscall (which you
may have gotten with the "man 2 open" command), you can, from the NAME
section, even if you're not a programmer, figure out that open opens a
file.

-- 
laurel at sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org



More information about the Techtalk mailing list