semget(2) DG/UX 5.4R3.00 semget(2)
NAME
semget - get a set of semaphores
SYNOPSIS
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int semget (key, nsems, semflg)
keyt key;
int nsems;
int semflg;
where:
key A user-defined name for the semaphore set
nsems The requested number of semaphores in the semaphore set
semflg A set of flags indicating the requested permission state of
the semaphore set, whether a new semaphore set should be
created, and whether the semaphore set should be held
exclusively
DESCRIPTION
Semget returns the semaphore set identifier associated with key.
This semaphore set identifier may then be used in other semaphore set
operations as specified by semctl and semop. Semget can be used to
get the semaphore set identifier of an already existing semaphore set
or to create a new semaphore set with nsems semaphores.
Four options are available:
⊕ Create a private semaphore set.
In this case, key is IPC_PRIVATE.
A process can create a "private" semaphore set by using the
special IPC_PRIVATE key. The system will create a semaphore
set identifier that is private to the process. The semaphore
set identifier will not be returned to other processes
regardless of what key value they specify.
The newly created semaphore set can be shared among other
processes by distributing the semaphore set identifier.
A process can make multiple semget operations specifying
IPC_PRIVATE. The identifiers returned will be unique and the
associated semaphore sets will be different.
⊕ Find key if already defined.
In this case, the IPC_CREAT and IPC_EXCL bits of semflg are
clear and key is not IPC_PRIVATE.
Licensed material--property of copyright holder(s) 1
semget(2) DG/UX 5.4R3.00 semget(2)
The semaphore set identifier associated with the given key is
returned. An error is given if one of the following
conditions hold:
⊕ No semaphore set identifier is associated with key.
⊕ A semaphore set identifier is associated with key but
the permission rights of the semaphore set do not
include those specified by the low-order 9 bits of
semflg.
⊕ A semaphore set identifier is associated with key but
nsems is non-zero and the number of semaphores in the
semaphore set is less than nsems.
⊕ Create only if key not already defined.
In this case, the IPC_CREAT and IPC_EXCL bits of semflg are
both set and key is not IPC_PRIVATE.
If a semaphore set identifier already exists for key an error
is returned. Otherwise, a semaphore set identifier and
associated semaphore set are created. The semaphore set
identifier will be returned to other processes that specify
the same key value.
⊕ Find key if already defined, otherwise create.
In this case, the IPC_CREAT bit of semflg is set, the IPC_EXCL
bit of semflg is clear, and key is not IPC_PRIVATE.
If a semaphore set identifier already exists for key, this is
identical to the second option above). Otherwise, this is
identical to the third option above.
If a new semaphore set is created, its attributes are initialized as
follows:
⊕ The semaphore set creator's user id (sem_perm.cuid) and the
semaphore set's user id (sem_perm.uid) are set to the
effective user id of the calling process.
⊕ The semaphore set creator's group id (sem_perm.cgid) and the
semaphore set's group id (sem_perm.gid) are set to the
effective group id of the calling process.
⊕ The semaphore set's permission rights (in sem_perm.mode) are
set to the low-order 9 bits of semflg.
⊕ The number of semaphores in the semaphore set (sem_nsems) is
set to nsems.
⊕ The most recent time a semop operation was performed
(sem_otime) is set to the zero value.
Licensed material--property of copyright holder(s) 2
semget(2) DG/UX 5.4R3.00 semget(2)
⊕ The most recent time the semaphore set attributes were changed
(sem_ctime) is set to the current time.
⊕ The semaphore's value is set to zero.
⊕ The process id of the last process to perform an operation on
the semaphore is set to zero.
⊕ The number of processes waiting for the semaphore's value to
become zero is zero.
⊕ The number of processes waiting for the semaphore's value to
increase is zero.
⊕ No processes have a semaphore adjustment value for the
semaphore.
ACCESS CONTROL
See the description of the exception conditions EACCES below.
RETURN VALUE
semid A non-negative integer that identifies the semaphore set
associated with key.
-1 An error occurred. errno is set to indicate the error.
DIAGNOSTICS
If a semaphore set identifier exists for key, errno may be set to one
of these values:
EACCES The permission rights of the semaphore set do not include
those specified by the low-order 9 bits of semflg.
EINVAL nsems is non-zero, and the number of semaphores in the set
associated with key is less than nsems.
EEXIST Both the IPC_CREAT and IPC_EXCL bits of semflg are set.
If a semaphore set identifier does not exist for key, errno may be
set to one of these values:
EINVAL nsems is either less than or equal to zero or greater than
the system-imposed limit.
ENOENT The IPC_CREAT bit of semflg is clear.
ENOSPC Creating the new semaphore set would cause the system-
imposed limit on the maximum number of allowed semaphore
sets system-wide to be exceeded.
SEE ALSO
intro(2), ipcrm(1), ipcs(1), semctl(2), semop(2), stdipc(3C).
Licensed material--property of copyright holder(s) 3