This document was created by man2html using the manual pages.
Section: Linux Programmer's Manual (2)
Return to NetAdminTools
semget - get a semaphore set identifier
int semget(key_t key,
This function returns the semaphore set identifier
associated with the argument
A new set of
semaphores is created if
has the value
or if no existing semaphore set is associated to
is asserted in
The presence in
of the fields
plays the same role, with respect to the existence
of the semaphore set, as the presence
in the mode argument of the
system call: i.e. the
function fails if
and a semaphore set already exists for
Upon creation, the low-order 9 bits of the argument
define the access permissions (for owner, group and others)
for the semaphore set.
These bits have the same format, and the same
meaning, as the mode argument in the
system calls (though the execute permissions are
not meaningful for semaphores, and write permissions mean permission
to alter semaphore values).
When creating a new semaphore set,
initializes the semaphore set's associated data structure
are set to the effective user-ID of the calling process.
are set to the effective group-ID of the calling process.
The low-order 9 bits of
are set to the low-order 9 bits of
is set to the value of
is set to 0.
is set to the current time.
(a don't care)
when a semaphore set is not being created.
must be greater than
and less than or equal to the maximum number of semaphores per semaphore set
If the semaphore set already exists, the access permissions are
If successful, the return value will be the semaphore set identifier
(a nonnegative integer), otherwise
is returned, with
indicating the error.
will be set to one of the following:
A semaphore set exists for
but the calling process does not have permission to access the set.
A semaphore set exists for
was asserting both
No semaphore set exists for
is less than 0 or greater than the limit on the number
of semaphores per semaphore set
or a semaphore set corresponding to
already exists, and
is larger than the number of semaphores in that set.
A semaphore set has to be created but the system has not enough memory for
the new data structure.
A semaphore set has to be created but the system limit for the maximum
number of semaphore sets
or the system wide maximum number of semaphores
would be exceeded.
isn't a flag field but a
If this special value is used for
the system call ignores everything but the low-order 9 bits of
and creates a new semaphore set (on success).
The followings are limits on semaphore set resources affecting a
System wide maximum number of semaphore sets: policy dependent.
Maximum number of semaphores per semid: implementation dependent
System wide maximum number of semaphores: policy dependent.
Values greater than
SEMMSL * SEMMNI
makes it irrelevant.
doesn't inhibit to other processes the access to the allocated
There is currently no intrinsic way for a process to ensure
exclusive access to a semaphore set.
only ensures (on success) that a new semaphore set will be created,
it doesn't imply exclusive access to the semaphore set.
The data structure associated with each semaphore in the set
isn't initialized by the system call.
In order to initialize those data structures, one has to execute a
subsequent call to
to perform a
command on the semaphore set.
SVr4 documents additional error conditions EFBIG, E2BIG, EAGAIN,
- RETURN VALUE
- CONFORMING TO
- SEE ALSO
Return to NetAdminTools,