HP-UX Reference (11i v2 03/08) - 2 System Calls (vol 5)

p
pstat(2) pstat(2)
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");
}
/*
* Example 6: List all the open files for the parent process
*/
{
pid_t target = getppid();
#define BURST ((size_t)10)
struct pst_fileinfo2 psf[BURST];
int i, count;
int idx = 0; /* index within the context */
(void)printf("Open files for process PID %d\n", target);
/* loop until all fetched */
while ((count = pstat_getfile2(psf, sizeof(struct pst_fileinfo2),
BURST, idx, target)) > 0) {
/* process them (max of BURST) at a time */
for (i = 0; i < count; i++) {
(void)printf("fd #%d\tFSid %x:%x\tfileid %d\n",
psf[i].psf_fd,
psf[i].psf_id.psf_fsid.psfs_id,
psf[i].psf_id.psf_fsid.psfs_type,
psf[i].psf_id.psf_fileid);
}
/*
* Now go back and do it again, using the
* next index after the current ’burst’
*/
idx = psf[count-1].psf_fd + 1;
}
if (count == -1)
perror("pstat_getfile2()");
#undef BURST
}
/*
* Example 7: Acquire information about a specific LWP
*/
HP-UX 11i Version 2: August 2003 13 Hewlett-Packard Company Section 2247