Operating System - HP-UX
1828371 Members
2902 Online
109976 Solutions
New Discussion

The output of ps -u command and pstat_getproc() is different.

 
RamaRao
Occasional Contributor

The output of ps -u command and pstat_getproc() is different.

Hi All,

I'm trying to get the size of the process, for that I'm using the command "UNIX95= ps -u udb -o vsz -o args".
I also have a program which gives the size of the process it uses pstat_getproc.

The following is the code that is used to get the process size,

struct pst_status pst;
unsigned long process_size;
if (pstat_getproc(&pst, sizeof(pst), (size_t)0, pid) != -1)
{
process_size = (size_t) (pst.pst_dsize+ pst.pst_tsize+ pst.pst_ssiz
e);
process_size *= sysconf(_SC_PAGE_SIZE); //convert # of pages to byt
es
process_size /= (1024); //return value is in KB
if (cmd != (char *) NULL)
strcpy(cmd, pst.pst_ucomm);
}

variable process_size will have the size of the process.

The output of ps -u is different from that of pstat_getproc(). ps -u value is larger than pstat_getproc.

Can any one tell me the reason for this and suggest me the correct command
Your help is appreciated.

Thanks,
RamaRao


5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: The output of ps -u command and pstat_getproc() is different.

Is the difference significant?

Based on your calculations it would seem your command might be more accurate than the ps command. But its supposedly reading the process table, so it can be confusing.

It might be how pstat_getproc works introducing the error.

It would be useful for us to see the output prior to making suggestions on how to change your code.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
RamaRao
Occasional Contributor

Re: The output of ps -u command and pstat_getproc() is different.

Hi Steven E Protter,

The difference between ps -u output and pstat_getproc() is very huge.
ps -u output is 696MB and pstar_getproc() output is 350MB. Now I'm in dilema on to use which command.

So please recommend the correct one and reason why it should be used would be great.

I would like to know the reason also, so could you please help me.
Nick W
Frequent Advisor

Re: The output of ps -u command and pstat_getproc() is different.

RamaRao

I would suggest you look at glance output for the process and then decide - perhaps one tool is giving the RSS (resident set size) and the other is reporting the total virtual memory set size (VSS)...?

Personally, I would trust the output from the ps command (assuming you have latest patches - latest for ps(1) is PHCO_31978)

HTH
Regards,
Nick
Amit Agarwal_1
Trusted Contributor

Re: The output of ps -u command and pstat_getproc() is different.

Hi Rama,

manpage of ps is misleading. You need to use '-o sz' to get the footprint of process in physical memory. The other option '-o vsz' gives the virtual memory footprint i.e. physical+swap area size.

-Amit
Ermin Borovac
Honored Contributor

Re: The output of ps -u command and pstat_getproc() is different.

sz and vsz from ps output can be related to pstat variables as follows. Please note that for vsz calculation you should use pst_v{d,t,s}size instead of pst_{d,t,s}size.

sz = pst.pst_dsize + pst.pst_tsize + pst.pst_ssize

vsz = (pst.pst_vdsize + pst.pst_vtsize + pst.pst_vssize) * _SC_PAGE_SIZE