Gets a set of semaphores. This function is OpenVMS Alpha and Integrity servers only. Format #include <sem.h> int semget (key_t key, int nsems, int semflg);
1 – Argument
key The key for which the associated semaphore identifier is returned. nsems Value used to initialize the sem_nsems member of the semid_ds data structure. See the description. semflg Flag used to initialize the low-order 9 bits of the sem_perm.mode member of the semid_ds data structure associated with the new semaphore. See the description. value The initial value to be given to the semaphore. This argument is used only when the semaphore is being created.
2 – Description
The semget function returns the semaphore identifier associated with key. A semaphore identifier with its associated semid_ds data structure and its associated set of nsems semaphores (see the <sys/sem.h> header file) is created for key if one of the following is true: o The key argument is equal to IPC_PRIVATE. o The key argument does not already have a semaphore identifier associated with it and (semflg &IPC_CREAT) is nonzero. When it is created, the semid_ds data structure associated with the new semaphore identifier is initialized as follows: o In the operation permissions structure sem_perm.cuid, sem_ perm.uid, sem_perm.cgid, and sem_perm.gid are set equal to the effective user ID and effective group ID, respectively, of the calling process. o The low-order 9 bits of sem_perm.mode are set equal to the low-order 9 bits of the semflg argument. o The variable sem_nsems is set equal to the value of the nsems argument. o The variable sem_otime is set equal to 0 and the variable sem_ ctime is set equal to the current time. o The data structure associated with each semaphore in the set does not need to be initialized. You can use the semctl function with the command SETVAL or SETALL to initialize each semaphore.
3 – Return Values
n Successful completion. The function returns a non-negative integer semaphore identifier. -1 Indicates an error. The function sets errno to one of the following values: o EACCES - A semaphore identifier exists for key, but operation permission as specified by the low-order 9 bits of semflg was not granted. o EEXIST - A semaphore identifier exists for key but ((semflg &IPC_CREAT) &&(semflg &IPC_EXCL)) is nonzero. o EFAULT - The arguments passed to the function are not accessible. o EINVAL - The value of nsems is either less than or equal to 0 or greater than the system-imposed limit, or a semaphore identifier exists for key, but the number of semaphores in the set associated with it is less than nsems and nsems is not equal to 0. o ENOENT - A semaphore identifier does not exist for key and (semflg &IPC_CREAT) is equal to 0. o ENOSPC - A semaphore identifier is to be created but the system-imposed limit on the maximum number of allowed semaphores system-wide will be exceeded. o EVMSERR - OpenVMS specific nontranslatable error code.