Operating System - HP-UX
1822522 Members
2692 Online
109642 Solutions
New Discussion юеВ

Re: Memory usage per process

 
Jimbo_7
Occasional Contributor

Memory usage per process

Hi, i know that the memory usage per process is treated previously in the forum, but I can't get correct values. The sum of processes does not even agree whith the Physical Memory or Shared Memory.

I need to know how i can get the memory use per process (Only RAM) and that the add of all process memory is agree with the RAM memory or the Shared Memory.

I can use procsize or ps.

Thanks
7 REPLIES 7
Geoff Wild
Honored Contributor

Re: Memory usage per process

Does this do it:

# cat /usr/local/bin/processmem
#!/bin/sh
# processmem - display memory claimed by a process
# gwild 03192004
#
if [ $# -lt 1 -o \( $# -gt 1 -a $# -lt 4 \) ]
then
echo "Usage:"
echo "processmem \"process\""
echo "Example:"
echo "processmem rpc"
exit 1
fi
echo " "

PROCESS=$1

mps=0
#for sz in `ps -elf | grep $PROCESS | grep -v grep | awk '{print $10}'`
for sz in `UNIX95= ps -e -o vsz=Kbytes -o ruser -o pid,args=Command-Line | sort -rnk1 | grep -v Kbytes | grep $PROCESS | awk '{print $1}'`
do
mps=`expr $mps + $sz`
done
#echo `expr $mps \* 4096`
echo "\nMemory claimed by $PROCESS: $mps Kbytes.\n"


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.
David de Beer
Valued Contributor

Re: Memory usage per process


Or use one of the following:

UNIX95= ps -eo 'vsz pid args' |sort -nr |head -20
UNIX95= ps -e -o "user,pcpu,cpu,vsz,pid,ppid,args" | sort -rnk4

Regards,
David de Beer.
Venkat_11
Regular Advisor

Re: Memory usage per process

Hi ,

I am trying to use these commands to find out the usage of physical memory by different processors. But in my server when i am trying to run these two command to check for sshd process. One command is showing up the sshd is running and the other one is not at all showing the sshd process. Here i am attaching the output of the commands gathered from my server. Please let me know how to find out sshd process is using the Physical Memory of swap because here when i am running glance its showing up 99% usage of physical memory and 45% on swap.

root# UNIX95= ps -eo 'vsz pid args' |sort -nr |head -20 | grep sshd
root#



root# UNIX95= ps -e -o "user,pcpu,cpu,vsz,pid,ppid,args" | sort -rnk4 | grep sshd | more
root 0.06 0 1708 25528 4569 sshd: agarcia@pts/240
root 0.02 1 1708 28674 4569 sshd: djrobins@pts/578
root 0.02 0 1708 19089 4569 sshd: lanier@pts/394
root 0.02 0 1708 19038 1 sshd: root@pts/91
root 0.02 0 1708 18510 4569 sshd: root@pts/587
root 0.02 0 1708 17804 4569 sshd: root@pts/583
root 0.02 0 1708 5114 4569 sshd: jaleman1@pts/42
root 0.02 0 1708 3226 4569 sshd: dcrawfor@pts/95
root 0.14 0 1644 3430 4569 sshd: eparker@pts/208
root 0.02 0 1644 27640 4569 sshd: dtravers@pts/534
root 0.02 0 1644 23153 4569 sshd: rjanak@pts/485
root 0.02 0 1644 21086 4569 sshd: rplancar@pts/400
root 0.02 0 1644 20666 4569 sshd: kearley@notty
root 0.02 0 1644 18601 4569 sshd: flores@pts/233
root 0.02 0 1644 16969 4569 sshd: scedillo@pts/87
root 0.02 0 1644 11236 4569 sshd: concur@notty
root 0.50 0 1580 17952 4569 sshd: sahlert@pts/325
root 0.29 0 1580 23635 4569 sshd: sbales@pts/239
root 0.18 0 1580 23990 4569 sshd: jquillan@pts/189
root 0.17 0 1580 26601 4569 sshd: nac@pts/417
root 0.16 0 1580 10666 4569 sshd: mweeks@pts/318
root 0.12 0 1580 13314 4569 sshd: btrzebia@pts/430
root 0.11 0 1580 4641 4569 sshd: root@pts/8
root 0.10 0 1580 23392 4569 sshd: klostak@pts/89
root 0.09 0 1580 22326 4569 sshd:



Please clarify my doubt

Thanks in advance
Venkat
Bill Hassell
Honored Contributor

Re: Memory usage per process

It is very important to NOT use grep to locate processes by name. grep has no clue that you want it to match the exact process name and not match on a user name like sshdave or lasshd3. The secret is -C as in:

UNIX95= ps -C sshd -o ruser,pid,ppid,args

As for tring to match memory usage, Unix has many, many memory maps and local process memory is just one. You have to add the buffer cache, the shared libraries, shared executables, memory mapped files, the kernel itself as well as shared memory between programs. It is quite difficult for a simple tool like ps to make sense of all this. For instance, a single program may have 20 copies but only one area of memory contains the instructions (called the text area in HP-UX terms), and that program may be one of dozens of programs that use a single shared library. This memory area cannot be added to a sinlge program's usage as it would not represent true memory usage.

Similarly, a program may access a shared memory area that other programs use. These shared resources are essentially a kernel resource because multiple programs may use these shared areas. Another area is the buffer cache. All programs that read/write files will use the buffer cache.

Your best bet is to look at the Glance stats for each interesting process (ones that consume a lot of memory). Look at the online help for Glance to explain the virtual versus resident set size (VSS, RSS).


Bill Hassell, sysadmin
Thomas D. Dial
New Member

Re: Memory usage per process

On an rp8400, with HP-UX 11.11, the suggested variants of ps such as
UNIX95= ps -eo 'vsz pid args'
appear to give virtual size or count shared memory multiply. Adding the totals in one instance givs a total of 27+ GB on a machine with 8 GB of real memory. (Unless the ps output is off by a factor of about 10: The top output shows about 2.7 GB in use and 3.2 GB free.)

UNIX95= ps -eo 'vsz sz pid args' |\
awk '{mem += $1; pgs += $2};END {printf "% 19d\n", pgs*4}' gives 28144708.
Thomas D. Dial
New Member

Re: Memory usage per process

My objective is to determine the amount of non-shared memory each process uses.

On an rp8400, with HP-UX 11.11, the suggested variants of ps such as
UNIX95= ps -eo 'vsz pid args'
appear to give virtual size or count shared memory multiply. Adding the totals in one instance givs a total of 27+ GB on a machine with 8 GB of real memory. (Unless the ps output is off by a factor of about 10: The top output shows about 2.7 GB in use and 3.2 GB free.)

UNIX95= ps -eo 'vsz sz pid args' |\
awk '{mem += $1; pgs += $2};END {printf "% 19d\n", pgs*4}' gives 28144708.

A. Clay Stephenson
Acclaimed Contributor

Re: Memory usage per process

Well, your objective may not be include shared memory but that dog just ain't gonna hunt -- at least with command-line tools. Shared memory does not only mean IPCS shared memory segments but also shared text. For example, you may have 10 instances of vi running and while they each have separate and distinct data segments, they share a common text segment (the program code) as well as functions from shared libraries which might be in use by hundreds of processes. Trying to do the kind of calculations that you are doing is all but impossible with simple scripts.
If it ain't broke, I can fix that.