HP-UX Reference (11i v2 04/09) - 2 System Calls (vol 5)
p
pstat(2) pstat(2)
int total_execs = 0;
for (i = 0; i < nspu; i++) {
int execs = psp[i].psp_sysexec;
total_execs += execs;
(void)printf("%d exec()s on processor #%d\n",
execs, i);
}
(void)printf("total execs for the system were %d\n",
total_execs);
}
else
perror("pstat_getdynamic");
}
else
perror("pstat_getdynamic");
}
/*
* Example 3: get information about all per-process -- 10 at a time
* done this way since current count of active processes unknown
*/
{
#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 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++) {
(void)printf("pid is %d, command is %s\n",
pst[i].pst_pid, pst[i].pst_ucomm);
}
/*
* now go back and do it again, using the next index after
* the current ’burst’
*/
idx = pst[count-1].pst_idx + 1;
}
if (count == -1)
perror("pstat_getproc()");
#undef BURST
}
/*
* Example 4: Get a particular process’s information
*/
{
struct pst_status pst;
int target = (int)getppid();
if (pstat_getproc(&pst, sizeof(pst), (size_t)0, target) != -1)
(void)printf("Parent started at %s", ctime(&pst.pst_start));
else
perror("pstat_getproc");
}
/*
* Example 5: get information about all shared memory segments
*/
{
HP-UX 11i Version 2: September 2004 − 12 − Hewlett-Packard Company Section 2−−251