Manual Page Search Parameters

SEMGET(2) System Calls Manual SEMGET(2)


semgetget semaphore set


#include <sys/sem.h>
semget(key_t key, int nsems, int semflg);


The semget() system call returns the semaphore identifier associated with key.
A new set containing nsems semaphores is created if either key is equal to IPC_PRIVATE, or key does not have a semaphore set associated with it and the IPC_CREAT bit is set in semflg.
The access modes of the created semaphores is specified in semflg as a bitwise OR of zero or more of the following values:
SEM_A        alter permission for owner 
SEM_R        read permission for owner 
SEM_A >> 3   alter permission for group 
SEM_R >> 3   read permission for group 
SEM_A >> 6   alter permission for other 
SEM_R >> 6   read permission for other
If a new set of semaphores is created, the data structure associated with it (the semid_ds structure, see semctl(2)) is initialized as follows:


semget() returns a non-negative semaphore identifier if successful. Otherwise, -1 is returned and errno is set to reflect the error.


The caller has no permission to access a semaphore set already associated with key.
Both IPC_CREAT and IPC_EXCL are set in semflg, and a semaphore set is already associated with key.
nsems is less than or equal to 0 or greater than the system limit for the number in a semaphore set.
A semaphore set associated with key exists, but has fewer semaphores than the number specified in nsems.
A new set of semaphores could not be created because the system limit for the number of semaphores or the number of semaphore sets has been reached.
IPC_CREAT was not set in semflg and no semaphore set associated with key was found.


semctl(2), semop(2), ftok(3)
November 15, 2014 OpenBSD-current