semget(PCI) 6 January 1993 semget(PCI) Name semget - get set of semaphores Syntax #include <pcilib.h> #include <memmdl.h> #include <ipc.h> int semget (key, nsems, semflg) key_t key; int nsems, semflg; Description semget returns the semaphore identifier associated with key. The operations are performed on the current host (as specified in the most recent dflthost call). A semaphore identifier and associated data structure and set containing nsems semaphores (see Intro(PCI)) are created for key if one of the fol- lowing is true: + key is equal to IPCPRIVATE. + key does not already have a semaphore identifier associated with it, and (semflg & IPCCREAT) is "true." On creation, the data structure associated with the new semaphore iden- tifier is initialized as follows: + semperm.cuid, semperm.uid, semperm.cgid, and semperm.gid are set to the effective user ID and effective group IDs, respectively, of the calling process. + The low-order nine bits of semperm.mode are set equal to the low- order nine bits of semflg. + semnsems is set to the value of nsems. + semotime is set to zero, and semctime is set to the current UNIX op- erating system time. semget fails if one or more of the following are true: [EINVAL] nsems is either less than or equal to zero or greater than the UNIX operating system-imposed limit. [EACCES] A semaphore identifier exists for key, but operation permission (see Intro(PCI)) as specified by the low-order nine bits of semflg would not be granted. [EINVAL] A semaphore identifier exists for key, but the number of sema- phores in the set associated with it is less than nsems and nsems is not equal to zero. [ENOENT] A semaphore identifier does not exist for key, and (semflg & IPCCREAT) is "false." [ENOSPC] A semaphore identifier is to be created, but the number of semaphore identifiers would exceed the system maximum allowed for that host. [EEXIST] A semaphore identifier exists for key, but (semflg & IPCCREAT) & (semflg & IPCEXCL) is "true." Return value On successful completion, a semaphore identifier returns. Otherwise, a value of -1 returns and errno is set to indicate the error. See also dflthost(PCI), Intro(PCI), semctl(PCI), semop(PCI)