| Date: Mon, 29 May 2006 17:50:04 +0200
| From: "Mark Clifford" <markcliff at gmail.com>
|
| I wanna [ print ] the memory used from a java process
| using a shell script.
|
| Now i thought i could use the following:
| ps -uusername -o vsz, comm | grep java
|
| Which returns:
| 182332 java
|
| it seems to just return a size that is not the same as
| the one if i do a top command. Why is this[? ... ]
different commands compute "the amount of memory used"
differently. the hard part of the computation is what
to do about memory that is, or could be, shared (used)
by multiple processes, such as text (code) and shared
memory (nominally data, i.e. shmat(2) et al.).
one method is to simply add it all up. the problem
here is the value is "too large" when there there are
many sharers.
another is to divide the total for shared regions by
the number of sharers. the problem here is the value
will fluxuate up-and-down as processes start/exit.
a weighted average is therefore sometimes used. the
value will still fluxuate, but "slower", and it is
rather more obscure how the value relates to anything.
also, there are different weighing algorithms and time
intervals, increasing the number of different values
printed.
and so on ....
I would suggest either picking a number you believe in,
which probably means one adequate for yer purpose, or
defining yer own algorithm, or reworking the issue so
that you don't need this hard-to-define number. (or
use static binaries, where there is less of an issue.)
cheers!
-blf-
--
Experienced (20+ yrs) kernel/software Eng: | Brian Foster Montpellier,
• Unix, embedded, &tc; • Linux; • doc; | blf at utvinternet.ie FRANCE
• IDL, automated testing, process, &tc. | Stop E$$o (ExxonMobile)!
Résumé (CV) http://www.blf.utvinternet.ie | http://www.stopesso.com
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!