PSTAT Interfaces

21
information for a single semaphore set may be obtained by setting elemcount to zero and setting
index to the semid of that semaphore set.
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-semid shortcut is used and there is no semaphore set with that ID.
EFAULT is set if buf points to invalid address.
Example:
#include <sys/pstat.h>
#include <stdlib.h>
void main(void)
{
struct pst_ipcinfo psi;
struct pst_seminfo *pssp;
size_t semmni;
int i, semsets_inuse, sems_inuse = 0;
if ((pstat_getipc (&psi, sizeof(psi), 1, 0) == -1) &&
(errno != EOVERFLOW)) {
printf ("\n Could not get ipc info\n");
exit(1);
}
semmni = psi.psi_semmni;
pssp = (struct pst_seminfo *)
calloc(semmni, sizeof (struct pst_seminfo));
if (!pssp) {
printf("\n No memory\n");
exit(1);
}
semsets_inuse = pstat_getsem(pssp,
sizeof(struct pst_seminfo), semmni, 0);
for (i = 0; i < semsets_inuse; i++) {
sems_inuse += pssp[i].pse_nsems;
}
free (pssp);
printf("\n Total Semaphores sets: %d", semmni);
printf("\n Active Semaphores sets: %d", semsets_inuse);
printf("\n Total Semaphores: %d", psi.psi_semmns);
printf("\n Active Semaphores: %d", sems_inuse);
}
4.19 pstat_getshm()
Synopsis:
int pstat_getshm(struct pst_shminfo *buf, size_t elemsize, size_t elemcount, int index);
Description:
Returns information about System V shared memory segments. Each structure returned
describes one segment identifier on the system. For each instance data up to a maximum of
elemsize bytes are returned in the structs pst_shminfo pointed to by buf. The elemcount
parameter specifies the number of structs pst_shminfo that available at buf. The index parameter