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' :
# of semaphores in array (0 <= nsems <= SEMMSL <= SEMMNS)
0 => dont care can be used when not creating the resource.
If successful you always get access to the entire array
* semflg :
IPC_CREAT used to create a new resource
IPC_EXCL used with IPC_CREAT to ensure failure if the
rwxrwxrwx access permissions.
* returns : semid on success. -1 on failure.
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.
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
ENOENT : Resource does not exist and IPC_CREAT not specified.
EACCES : (procure) do not have permission for specified access.
automatically generated by