The
semget() system call returns the semaphore identifier associated with
key.
A new set containing
nsems semaphores is created if either
key is equal to
IPC_PRIVATE, or
key does not have a semaphore set associated with it and the
IPC_CREAT bit is set in
semflg. If both the
IPC_CREAT bit and the
IPC_EXCL bit are set in
semflg, and
key has a semaphore set associated with it already, the operation will fail.
If a new set of semaphores is created, the data structure associated with it (the
semid_ds structure, see
semctl(2)) is initialized as follows:
•
sem_perm.cuid and sem_perm.uid are set to the effective uid of the calling process.
•
sem_perm.gid and sem_perm.cgid are set to the effective gid of the calling process.
•
sem_perm.mode is set to the lower 9 bits of semflg.
•
sem_nsems is set to the value of nsems.
•
sem_ctime is set to the current time.