OpenBSD manual page server

Manual Page Search Parameters

SEM_OPEN(3) Library Functions Manual SEM_OPEN(3)

sem_open, sem_close, sem_unlinkopen and close named semaphores

#include <semaphore.h>

sem_t *
sem_open(const char *name, int oflag, ...);

int
sem_close(sem_t *sem);

int
sem_unlink(const char *name);

The () function opens and returns a named semaphore. The () function closes a previously opened named semaphore without removing it. The () function removes the named semaphore from the system without closing it.

On success, sem_open() returns a pointer to a semaphore. sem_close() and sem_unlink() return 0 on success. sem_open() returns SEM_FAILED and sets errno to indicate an error. sem_close() and sem_unlink() return -1 and set errno to indicate an error.

It is an error to call sem_close() with an unnamed semaphore or to call sem_destroy(3) with a named semaphore.

sem_open() may fail if:

[]
Insufficient memory is available.
[]
An attempt was made to open a shared semaphore owned by another user.

sem_unlink() may fail for any of the reasons listed in unlink(2).

sem_destroy(3), sem_getvalue(3), sem_init(3), sem_post(3), sem_wait(3)

sem_open(), sem_close(), and sem_unlink() appear in ISO/IEC 9945-1:1996 (“POSIX.1”). This implementation deviates from the standard by permitting less sharing.

February 11, 2023 OpenBSD-current