Operating System - HP-UX
1833958 Members
2319 Online
110063 Solutions
New Discussion

Re: Resident memory usage (whitout top)

 
SOLVED
Go to solution
Marcelo De Florio_1
Frequent Advisor

Resident memory usage (whitout top)

How can i obtain the resident memory usage for a one process (whitout top)?

MDF
Marcelo De Florio
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor

Re: Resident memory usage (whitout top)

Hi Marcelo:

I would do something like this:

UNIX95= ps -p ${MYPID} -o "args,vsz,sz"

vsz is the size in KB of the core image and sz in the total number of text,data, and stack pages of the process. The space after UNIX95= is required.

Clay
If it ain't broke, I can fix that.
Marcelo De Florio_1
Frequent Advisor

Re: Resident memory usage (whitout top)

Clay, thanks, but i need the resident size of process, vsz or sz return the size of process. Can i obtain this?

MDF
Marcelo De Florio
Praveen Bezawada
Respected Contributor

Re: Resident memory usage (whitout top)

Hi
You can use the below commands

sar -o sarfile 2 2 # Produces a binary sarfile
sar -Af sarfile > sar.report

You can get the process resident statistics in the report file.

...PRB...
nancy rippey
Trusted Contributor

Re: Resident memory usage (whitout top)

If you have glance installed you can find it that way.
start glance
select 's' for process
entry the pid

If you are using the gui version of glance
start gpm
select reports
process list
click on the process name
select reports
process memory regions
for further info.
select reports again
process resources
nrip
linuxfan
Honored Contributor

Re: Resident memory usage (whitout top)

Hi Marco,

To sort the process based on the resided memory sizes,
UNIX95= ps -e -o vsz=Kbytes -o pid,args=Command-Line|sort -rnk1

you can put this in your .kshrc as a variable as well. For eg:
psmem="UNIX95= ps -e -o vsz=Kbytes -o ruser,pid,args=Command-Line|sort -nrk2"
(once you source your .kshrc, then just run psmem and it will list out your process sorted through the resident memory sizes-the output will list the size, loginid, pid, process name).

To just look for a process do a
psmem |grep $PID

-HTH
I am RU
They think they know but don't. At least I know I don't know - Socrates
linuxfan
Honored Contributor

Re: Resident memory usage (whitout top)

Hi Marco,

Please disregard my previous post, it does not list you the RSS of the process, like clay said, vsz lists the size of the core image of the process and sz lists the size in physical pages of the core image including text, data and stack space.
Some of the other options is to use the -d option for top and grep for the RSS value. or like nancy said, you might have to use glance.

The question i had is are you trying to achieve this in a script?

-Regards
I am RU
They think they know but don't. At least I know I don't know - Socrates
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Resident memory usage (whitout top)

Hi Marcelo:

Without top or Glance, you will have to do this with c using the pstat_getdynamic() function to get an array of processes and then using the pstat_getproc() to loop through the
array until you find your pid. The pst_status struct contains the data you want although at best it is an approximation since this data is constantly changing.

Someone may have written a perl module to do this but since it is so easy in C that whenever I've needed to do anything like this, I can usually whip it up in a few minutes.

Clay
If it ain't broke, I can fix that.
Wodisch
Honored Contributor

Re: Resident memory usage (whitout top)

Hello Marcelo,

if you can find a "quite" time on your system, where no
(or almost no) processes are started anew, try to do
something like
vmstat 1 10
start-your-process-here
vmstat 1 10

"vmstat" usually needs a few seconds to "settle", so
doing it ten timesshould take care of that ;-)
And, well, if nothing else is started in between the two
"vmstat" commands, just subtract the averages of the,
say, last 3 of each of them.
The column you are interested in is "free" and its unit
is in "pages" of course, which usually are 4096bytes
each (check with "chatr" onto the codefile of your
process).
Not really precise, but it should give you an idea about
it ;-)

HTH,
Wodisch
Jerry Zhang
Frequent Advisor

Re: Resident memory usage (whitout top)

This command will give you RSS in 4MB pages:
$ ps -elf |grep Proc_name |grep -v grep |awk '{print $10}'