System Interface Guide

POSIX Semaphores

POSIX semaphores are much lighter weight than are System V semaphores. A POSIX semaphore structure defines a single semaphore, not an array of up to twenty-five semaphores.

The POSIX semaphore interfaces are

sem_open(3RT)

Connects to, and optionally creates, a named semaphore 

sem_init(3RT)

Initializes a semaphore structure (internal to the calling program, so not a named semaphore) 

sem_close(3RT)

Ends the connection to an open semaphore 

sem_unlink(3RT)

Ends the connection to an open semaphore and causes the semaphore to be removed when the last process closes it 

sem_destroy(3RT)

Initializes a semaphore structure (internal to the calling program, so not a named semaphore). 

sem_getvalue(3RT)

Copies the value of the semaphore into the specified integer 

sem_wait(3RT), sem_trywait(3RT)

Blocks while the semaphore is held by other processes or returns an error if the semaphore is held by another process 

sem_post(3RT)

Increments the count of the semaphore