Go to main content

man pages section 2: System Calls

Exit Print View

Updated: Thursday, June 13, 2019
 
 

semids(2)

Name

semids - discover all semaphore identifiers

Synopsis

#include <sys/sem.h>

int semids(int *buf, uint_t nids, uint_t *pnids);

Description

The semids() function copies all active semaphore identifiers from the system into the user-defined buffer specified by buf, provided that the number of such identifiers is not greater than the number of integers the buffer can contain, as specified by nids. If the size of the buffer is insufficient to contain all of the active semaphore identifiers in the system, none are copied.

Whether or not the size of the buffer is sufficient to contain all of them, the number of active semaphore identifiers in the system is copied into the unsigned integer pointed to by pnids.

If nids is 0 or less than the number of active semaphore identifiers in the system, buf is ignored.

Return Values

Upon successful completion, semids() returns 0. Otherwise, −1 is returned and errno is set to indicate the error.

Errors

The semids() function will fail if:

EFAULT

The buf or pnids argument points to an illegal address.

Usage

The semids() function returns a snapshot of all the active semaphore identifiers in the system. More may be added and some may be removed before they can be used by the caller.

Examples

Example 1 semids() example

This is sample C code indicating how to use the semids() function.

void
examine_semids()
{
     int *ids = NULL;
     uint_t nids = 0;
     uint_t n;
     int i;

     for (;;) {
          if (semids(ids, nids, &n) != 0) {
               perror("semids");
               exit(1);
          }
          if (n <= nids)     /* we got them all */
               break;
          /* we need a bigger buffer */
          ids = realloc(ids, (nids = n) * sizeof (int));
     }   

     for (i = 0; i < n; i++)
          process_semid(ids[i]);

     free(ids);
}

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
MT-Level
Async-Signal-Safe

See Also

ipcrm(1), ipcs(1), Intro(2), semctl(2), semget(2), semop(2), attributes(7)