HP-UX Reference (11i v3 07/02) - 2 System Calls (vol 5)

p
pstat(2) pstat(2)
/* 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) {
size_t num_shm = psi.psi_shmmni;
pss = (struct pst_shminfo *)
malloc(num_shm * sizeof(struct pst_shminfo));
(void)memset(pss,0,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("%lld\t%#llx\t%llu\n",
pss[i].psh_uid, pss[i].psh_key,
pss[i].psh_segsz);
}
}
else
perror("pstat_getshm");
}
else
310 Hewlett-Packard Company 20 HP-UX 11i Version 3: February 2007