Next: semop, Previous: Semaphores, Up: Semaphores
A semaphore array is allocated by a semget system call:
semid = semget (key_t key, int nsems, int semflg);
key
: an integer usually got from ftok
or IPC_PRIVATE
nsems
:
An array of nsems semaphores is allocated if there is no resource
corresponding to the given key. The access permissions specified are
then copied into the sem_perm
struct for the array along with the
user-id etc. The user must use the IPC_CREAT flag or key = IPC_PRIVATE
if a new resource is to be created.
Errors:
EINVAL : nsems not in above range (allocate).
nsems greater than number in array (procure).
EEXIST : (allocate) IPC_CREAT | IPC_EXCL specified and resource exists.
EIDRM : (procure) The resource was removed.
ENOMEM : could not allocate space for semaphore array.
ENOSPC : No arrays available (SEMMNI), too few semaphores available (SEMMNS).
ENOENT : Resource does not exist and IPC_CREAT not specified.
EACCES : (procure) do not have permission for specified access.