Operating System - HP-UX
1819879 Members
2573 Online
109607 Solutions
New Discussion юеВ

information about a particular process in HPUX

 
SOLVED
Go to solution
Sathish_3
Occasional Contributor

information about a particular process in HPUX

How to obtain the information about a particular process in HPUX. I just know the name, path (optional) and arguments (optional) of the process. I'm currently using pstat_getproc() which is returning the information about all processes.

i.e pstat_getproc(&pst,sizeof(pst),(size_t)1,idx))
where idx=0
pst is of type struct pst_status.

6 REPLIES 6
Dave Olker
Neighborhood Moderator

Re: information about a particular process in HPUX

Hi Satish,

According to the pstat_getproc() man page:

_____________________________________

As a shortcut, information for a single process may be obtained by setting elemcount to zero and setting index to the PID of that process.

_____________________________________

Have you tried calling pstat_getproc() in this manner?

Regards,

Dave


I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Dave Olker
Neighborhood Moderator

Re: information about a particular process in HPUX

Also, I guess if you only know the name of the process you could use the "ps" command to get the PID and then call pstat_getproc() as indicated in my previous post to get the information about this process.

Dave


I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Duncan Galbraith
Frequent Advisor

Re: information about a particular process in HPUX

I agree with Dave, except about using 'ps' to get the PID.
You would be much safer to compare the returned info (.pst_cmd) with your command name and once you have a match you know you have the right pstat structure to extract whatever you want (so you don't even need to call pstat_getproc on the individual PID.
Sathish_3
Occasional Contributor

Re: information about a particular process in HPUX

As you guys have mentioned, I've tried ps on the first case. But the os responds very slowly for that command.

However if I use pstat_getproc it retrieves each process one by one. I don't know the pid. so i can't use the shortcut method. But i guess that we have to loop through all processes until we get the right one.

The command is supposed to be used in this way:
struct pst_status pst;
.
.
.

while(pstat_getproc(&pst,sizeof(pst),(size_t)1,idx)>0)
{
idx=(int)pst.pst_idx+1;

if( strcmp(basename(pst.pst_cmd,ourprocname)==0)
{

.... our code ......
break;
}
}






Mike Stroyan
Honored Contributor

Re: information about a particular process in HPUX

Looping through the processes with pstat_getproc and strcmp is really quite quick. It shouldn't be a performance problem with any reasonable number of processes running.
Mike Stroyan
Honored Contributor
Solution

Re: information about a particular process in HPUX

Notice that you don't have to call pstat_getproc for each process. You can pass in an array and get data for several processes in each call.

#define BURST ((size_t)10)
struct pst_status pst[BURST];
int i, count;
int idx = 0; /* index within the context */

/* loop until count == 0, will occur when all have been returned */
while ((count = pstat_getproc(pst, sizeof(pst[0]), BURST, idx)) > 0)
{
/* got count (max of BURST) this time. process them */
for (i = 0; i < count; i++) {
if (command && strcmp(pst[i].pst_ucomm, command))
continue; /* doesn't match command */