pstat.2 (2010 09)

p
pstat(2) pstat(2)
count = 0;
}
else if ((ret == -1) && (errno == EOVERFLOW)) {
/* EOVERFLOW case: at least one Process context hit it,
so we find the one that caused this error. Neither of
the fields we are interested in has a validity macro
defined, so we just count the number of structures
returned to us */
for (i=0;i<BURST;i++) {
count++;
if (pst[i].pst_valid!=-1) {
break;
}
}
}
else if ((ret == -1)) {
/* error case */
perror("pstat_getproc()");
count = 0;
}
/* got count this time. process them */
for (i = 0; i < count; i++) {
(void)printf("pid is %lld, 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’ if there are potentially more to find
*/
if (count)
idx = pst[count-1].pst_idx + 1;
} while (count);
#undef BURST
}
Example 5
Get information about our parent using
pstat_getproc()
.
main()
{
struct pst_status pst;
int target = (int)getppid();
(void)memset(&pst,0,sizeof(struct pst_status));
if (pstat_getproc(&pst, sizeof(pst), (size_t)0, target) != -1)
(void)printf("Parent real uid is %lld\n", pst.pst_uid);
else
perror("pstat_getproc");
}
Example 6
Get information about all shared memory segments.
main()
{
struct pst_ipcinfo psi;
struct pst_shminfo *pss;
(void)memset(&psi,0,sizeof(psi));
if (pstat_getipc(&psi, sizeof(psi), (size_t)1, 0) != -1) {
20 Hewlett-Packard Company 20 HP-UX 11i Version 3: September 2010