Operating System - HP-UX
1847855 Members
2682 Online
104021 Solutions
New Discussion

List top 10 user process sort by memory usage

 
Matthew_50
Valued Contributor

List top 10 user process sort by memory usage

Is it possible that 'top' able to sort by 'RES' column ?

Or when I use 'UNIX95= ps -e -o ruser,vsz,sz,pid,ppid,args |sort -rnk3' the total sz calculate value is not equal to my physical memory size, very annony question for me,

How should I do to convert the sz column value into MegaBytes or KBytes, as I heard from RC, the sz is 4k pages, Can anyone give me the convert formula ? thank you.
5 REPLIES 5
Sridhar Bhaskarla
Honored Contributor

Re: List top 10 user process sort by memory usage

Hi Matthew,

Well.. Simply adding the 'memory' used by all processes is not going to fill up your balance sheet. You will need to add buffer cache, dynamic memory buckets used by kernel, shared memory segments etc., in your calculations.

If you have glance, use it to get the picture. sz is in pages which is 4096 bytes by default. TO get the next level, devide it by 1024. For ex., 4096(b)/1024 = 4k similarly 4096(k)/1024=4MB.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Matthew_50
Valued Contributor

Re: List top 10 user process sort by memory usage

------ cut -----------------------
ruser vsz sz pid
operapp1 137352 34338 10550
operapp2 144004 32856 5694
operapp3 125064 31266 9423
operapp4 125064 31266 8582
operapp5 86120 21434 17170
operapp6 83080 20770 10812
------ cut -----------------------

for example pid 10550, sz is 34338
use the fomula
(34338*4096)/(1204*1024) equal to 134MBytes,
Is this right ?
Fred Ruffet
Honored Contributor

Re: List top 10 user process sort by memory usage

You're right but, IMHO, it is easiest to use vsz wich is the same as sz, but in KB.

As said, the sum you will get will not tell you how many memory is really used on your system. There are many other usage of memory (for example, you use Oracle, so "IPCS -mb" will show you shared memory segments).

Due to rounding and other misterious things, values given by top, ps or glance may vary. So don't expect an exact calculation ("but where is my missing KB ?" :) ).

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Steve Steel
Honored Contributor

Re: List top 10 user process sort by memory usage

Hi

These things are all relative

For a guide

#RSZ = Resident set size
#VSZ = Virtual set size
#
#RSZ is a subset of VSZ
#-the portion of the processes memory which is 'resident'
#in physical memory (ie not paged out).
#
#VSZ is the total size, including resident and non-resident pages.
#
#These values are totals, obtained by adding up the memory utilisation of the
#processes various memory segments (of which there can be lots).
#################################################################################
uname -a
echo -------------------------------------
/bin/rm /tmp/$PPID 2>/dev/null
if [ "$LOGNAME" = "root" ]
then
echo memory from kernel
name=$(file /stand/vmunix|grep 64)
if [ "$name" = "" ]
then
echo phys_mem_pages/D | adb /stand/vmunix /dev/kmem 2>/dev/null
else
echo phys_mem_pages/D | adb64 /stand/vmunix /dev/kmem 2>&1|grep -i page
fi
fi

echo " "
echo swap
echo -----------------
swapinfo -tm
echo " "
echo memory usage per process
echo "----------------------------------------------"
UNIX95= ps -e -o ruser,vsz,sz,pid,args > /tmp/$PPID
head -n 1 /tmp/$PPID
tail -n +2 /tmp/$PPID|
sort -rnk2
/bin/rm /tmp/$PPID 2>/dev/null


For real info

This excellent external hp ftp site will give you a goldmine on tools and info
Memory Usage - â What is using all of the memory?â

by:eric.herberholz@hp.com

Last modified: October 18, 2004

Full document is available at external ftp site: ftp://eh:spear9@hprc.external.hp.com/memory.htm
The "Table of Contents" is available in ITRC doc id MEMORYKBAN00000975


Steve S
If you want truly to understand something, try to change it. (Kurt Lewin)
Geoff Wild
Honored Contributor

Re: List top 10 user process sort by memory usage

Here's one I use called memtop...

# cat memtop

#!/bin/sh
# memtop - show top memory users and pid
# VSZ is in KB
echo "VSZ(KB) PID RUSER COMMAND"
UNIX95= ps -e -o 'vsz pid ruser args' |sort -nr|head -30

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.