HP-UX Reference (11i v1 00/12) - 2 System Calls (vol 5)
__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man2/!!!intro.2
________________________________________________________________
___ ___
p
pstat(2) pstat(2)
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’ 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
*/
{
struct pst_ipcinfo psi;
struct pst_shminfo *pss;
if (pstat_getipc(&psi, sizeof(psi), (size_t)1, 0) != -1) {
size_t num_shm = psi.psi_shmmni;
pss = (struct pst_shminfo *)
malloc(num_shm * sizeof(struct pst_shminfo));
if (pstat_getshm(pss, sizeof(struct pst_shminfo), num_shm, 0)
!= -1) {
int i;
(void)printf("owner\tkey\tsize\n");
for (i = 0; i < num_shm; i++) {
/* skip inactive segments */
if (!(pss[i].psh_flags & PS_SHM_ALLOC))
continue;
(void)printf("%d\t%#x\t%d\n",
pss[i].psh_uid, pss[i].psh_key,
pss[i].psh_segsz);
}
}
else
perror("pstat_getshm");
}
else
perror("pstat_getipc");
}
Section 2−−228 − 11 − HP-UX Release 11i: December 2000
___
___