Operating System - HP-UX
1847072 Members
5642 Online
110262 Solutions
New Discussion

How much memory a process use ?

 
SOLVED
Go to solution

How much memory a process use ?

I need to know how much memory a process is using, and how much shared memory.
It??s possible ?
8 REPLIES 8
Dave Chamberlin
Trusted Contributor

Re: How much memory a process use ?

Top will show the memory usage for each process.
Sajid_1
Honored Contributor

Re: How much memory a process use ?

If you have GlancePlus installed, then use it. It will give you the output you want:
# glance
# gpm
learn unix ..
Steve Steel
Honored Contributor

Re: How much memory a process use ?

Hi

Use the unix95 options of ps

#!/usr/bin/ksh
#
# Show processes sorted by size of core image
#
# Usage:
# psram [ quantity ]
#
# where quantity is the top RAM processes to show (default is 20)
#
set -u
if [ $# -gt 0 ]
then
TOPPROCS=$1
else
TOPPROCS=20
fi

MYNAME=$(basename $0)
TEMPFILE=/var/tmp/$MYNAME.$$
trap `rm -f $TEMPFILE > /dev/null 2>&1` 0 1 2 3 15

UNIX95= ps -e -o ruser,vsz,pid,args > $TEMPFILE
head -1 $TEMPFILE
DASH5="-----"
DASH25="$DASH5$DASH5$DASH5$DASH5$DASH5"
echo "$DASH5---- $DASH5- $DASH5 $DASH25$DASH25"
grep -v "VSZ COMMAND" $TEMPFILE | cut -c -78 | sort -rn -k2 | head -${TOPPROCS}
rm $TEMPFILE > /dev/null 2>&1
#### END OF SCRIPT

Or 2 lines to show top 20 by cpu with sz and vsz


1 echo " $(UNIX95= ps -e -o pcpu -o ruser -o sz -o vsz -opid -o args|head
-n1)"
2 UNIX95= ps -e -o pcpu -o ruser -o sz -o vsz -opid -o args|grep -v %CPU|
sort -nr|tail -n +2|head -n 20


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Chris Wilshaw
Honored Contributor

Re: How much memory a process use ?

Try

UNIX95= ps -ef -o pid,vsz,args | grep

This will give you

the process ID (pid)
the number of KB of memory used (vsz)
the command with arguments (args)

This lists total memory, I don't know if there is a way to display shard memory use.
A. Clay Stephenson
Acclaimed Contributor

Re: How much memory a process use ?

If you have Glance then yes you can.

Select Reports->Process List->Process Memory Regions.

If you don't have Glance, you can install a 30-day trial version from your Application CD set.
If it ain't broke, I can fix that.
Mike Stroyan
Honored Contributor

Re: How much memory a process use ?

If you are able to compile your own program to examine processes, then you can measure exactly what you want from the pstat_procvm function. I have attached a couple of examples. One reports lots of information about every memory region in every process. The other reports a summary of private and shared sizes. There are several types of shared regions, so you should decide if you want to count shared text areas, mmap areas, or just system V shared memory areas identified by a pst_type of PS_SHARED_MEMORY.

Re: How much memory a process use ?

Thank you for your answers, but i need more info.

I used a Steve Steel Script, and it returns me this value of a process PID 6381:

VSZ = 21528

The "ps -el" command returns:

SZ = 3606

The Myke Stroyan program, returns:

pid shared_vm shared_ram private_vm private_ram
6381 37456K 13788K 457272K 37852K

Who can explain this results ?

Mike Stroyan
Honored Contributor
Solution

Re: How much memory a process use ?

> VSZ = 21528
This is the virtual memory total for TEXT+DATA+STACK, measured as number of 4K pages.

> SZ = 3606
This is the virtual memory total for TEXT+DATA+STACK, measured as a multiple of 1K.

>pid shared_vm shared_ram private_vm private_ram
>6381 37456K 13788K 457272K 37852K
These are totals of shared memory segments and private memory segments, first virtual memory, and then actual RAM.

The "ps" data is only about a very limited part of what is mapped into the process. In the old classical unix model the TEXT+DATA+STACK was about all a process would use. In a typical process today a lot of the mapped memory is shared library text and data. It looks like this process must have a very large amount of other memory, probably mmap regions or system V shared memory regions.

The virtual memory number is the amount of addressable address range. That can be much more than the RAM number, because many pages can be either on disk or never accessed and never really allocated in RAM.

If you decipher the output of the full procvm tool, you can see the type and the length in pages of each segment in a process.