SEMGET
Return the semaphore set identifier associated with the argument ecx. Arguments
ecx | Key value. This key value is compared to existing key values that exist within the kernel for other semaphore sets. If IPC_PRIVATE is specified for this argument, a new semaphore sets will be created and the system call will ignore everything but the least significant 9 bits of esi.
edx | Number of semaphores. This argument can be 0 (a don't care) when a semaphore set is not being created. Otherwise edx must be greater than 0 and less than or equal to the maximum number of semaphores per semaphore set (SEMMSL).
esi | Operation flags:
`IPC_CREAT` | `Create if the semaphore set doesn't already exist in the kernel and argument in ecx is not IPC_PRIVATE.`
`IPC_EXCL` | `When used with IPC_CREAT, fail if semaphore set already exists.`
`` If both IPC_CREAT and IPC_EXCL and a semaphore set already exists for given key, then SEMGET fails with errno -EEXIST. (This is analogous to the effect of the combination "O_CREAT or O_EXCL" for sys_open.) Upon creation, the least significant 9 bits of the esi argument define the permissions (write permissions mean permission to alter semaphore values):
`S_IRUSR - owner has read permission S_IWUSR - owner has write permission S_IRGRP - group has read permission S_IWGRP - group has write permission S_IROTH - others have read permission S_IWOTH - others have write permission`
When creating a new semaphore set, SEMGET initialises the set's associated data structure semid_ds (see SEMCTL) as follows: `sem_perm.cuid` `and sem_perm.uid are set to the effective user ID of the calling process. sem_perm.cgid and sem_perm.gid are set to the effective group ID of the calling process. The least significant 9 bits of sem_perm.mode are set to the least significant 9 bits of esi. sem_nsems is set to the value of edx. sem_otime is set to 0. sem_ctime is set to the current time.` If the semaphore set already exists, the permissions are verified.
Return values If the function succeeds the return value is semaphore set identifier (a nonnegative integer). If the function fails the return value is one of the following errno values:
`-EACCES` | `A semaphore set exists for key, but the calling process does not have permission to access the set, and does not have the CAP_IPC_OWNER capability.`
`-EEXIST` | `A semaphore set exists for key and esi specified both IPC_CREAT and IPC_EXCL.`
`-EINVAL` | `edx is less than 0 or greater than the limit on the number of semaphores per semaphore set (SEMMSL), or a semaphore set corresponding to key already exists, and edx is larger than the number of semaphores in that set.`
`-ENOENT` | `No semaphore set exists for key and esi did not specify IPC_CREAT.`
`-ENOMEM` | `A semaphore set has to be created but the system does not have enough memory for the new data structure.`
`-ENOSPC` | `A semaphore set has to be created but the system limit for the maximum number of semaphore sets (SEMMNI), or the system wide maximum number of semaphores (SEMMNS), would be exceeded.`
Remarks The following limits on semaphore set resources affect the SEMGET call:
`SEMMNI` | `System wide maximum number of semaphore sets: policy dependent (this limit can be read and modified via the fourth field of /proc/sys/kernel/sem).`
`SEMMSL` | `Maximum number of semaphores per semid: implementation dependent (this limit can be read and modified via the first field of /proc/sys/kernel/sem).`
`SEMMNS` | `System wide maximum number of semaphores: policy dependent (this limit can be read and modified via the second field of /proc/sys/kernel/sem). Values greater than SEMMSL * SEMMNI makes it irrelevant.`