PSTAT Interfaces

22
specifies the starting index within the context of System V shared memory segments. As a
shortcut, information for a single shared memory segment may be obtained by setting elemcount
to zero and setting index to the shmid of that shared memory segment.
Return Value:
This call returns –1 on failure or number of instances copied to buf on success.
Errors:
EINVAL is set if the user's size declaration isn't valid.
EINVAL is set if index < 0.
ESRCH is set if the specific-shmid shortcut is used and there is no shared memory segment
with that ID.
EFAULT is set if buf points to invalid address.
Example:
Get information about all shared memory segments.
#include <sys/pstat.h>
#include <stdlib.h>
void main(void)
{
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 (!pss) {
printf(“\n No memory”);
exit(1);
}
if (pstat_getshm(pss, sizeof(struct pst_shminfo), num_shm, 0)
!= -1) {
int i;
printf("owner\tkey\tsize\n");
for (i = 0; i < num_shm; i++) {
/* skip inactive segments */
if (!(pss[i].psh_flags & PS_SHM_ALLOC))
continue;
printf("%l\t%#x\t%d\n",
(long) pss[i].psh_uid, pss[i].psh_key,
pss[i].psh_segsz);
}
} else {
perror("pstat_getshm");
}
free(pss);
} else {
perror("pstat_getipc");
}
}
4.20 pstat_getsocket()
Synopsis:
int pstat_getsocket(struct pst_socket *buf, size_t elemsize, struct pst_fid *fid);