semop(2) DG/UX 4.30 semop(2)
NAME
semop - Semaphore operations.
SYNOPSIS
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int semop (semid, sops, nsops)
int semid;
struct sembuf * sops;
unsigned nsops;
PARAMETERS
semid A semaphore set identifier.
sops An array of semaphore operations to perform.
nsops The number of semaphore operation records in
<sops>.
DESCRIPTION
Semop atomically performs <nsops> semaphore operations on
the semaphore set identified by <semid>. The semaphore
operation records are located in the array given by <sops>.
A semaphore operation has three components: a semaphore
number (sem_num), a semaphore operation (sem_op), and an
operation modifier (sem_flg). A semaphore operation is
performed by applying the operation, sem_op, modified by
sem_flg, to the semaphore specified by sem_num in the
semaphore set identified by <semid>. Sem_op specifies one
of three semaphore operations as follows:
* sem_op < 0: Perform_a_P_operation
If the semaphore's value is greater than or equal to the
absolute value of sem_op, the operation is successful. In
this case, the absolute value of sem_op is subtracted from
the semaphore's value, and, if the SEM_UNDO bit of sem_flg
is set, the absolute value of sem_op is added to the calling
process's semaphore adjustment value for the semaphore.
If the semaphore's value is less than the absolute value of
sem_op and the IPC_NOWAIT bit of sem_flg is set, semop will
return with the error condition EAGAIN.
If the semaphore's value is less than the absolute value of
sem_op and the IPC_NOWAIT bit of sem_flg is clear, semop
will suspend the calling process until:
Licensed material--property of copyright holder(s) Page 1
semop(2) DG/UX 4.30 semop(2)
* the semaphore's value becomes greater than or equal to
the absolute value of sem_op, in which case, the
operation is retried,
* <semid> is removed from the system, in which case,
semop will return with the error condition EIDRM, or
* the calling process receives a signal that is to be
caught, in which case, semop will return with the error
condition EINTR.
* sem_op > 0: Perform_a_V_operation
The value of sem_op is added to the semaphore's value and,
if the SEM_UNDO bit of sem_flg is set, the value of sem_op
is subtracted from the calling process's semaphore
adjustment value for the semaphore.
* sem_op == 0: Wait_for_zero
If the semaphore's value is zero, the operation is
successful.
If the semaphore's value is non-zero and the IPC_NOWAIT bit
of semflg is set, semop will return with the error condition
EAGAIN.
If the semaphore's value is non-zero and the IPC_NOWAIT bit
of sem_flg is clear, semop will suspend the calling process
until:
* the semaphore's value becomes zero or equal to the
absolute value of sem_op, in which case, the operation
is retried,
* <semid> is removed from the system, in which case,
semop will return with the error condition EIDRM, or
* the calling process receives a signal that is to be
caught, in which case, semop will return with the error
condition EINTR.
The operation performed by semop is the composition of the
individual operations given by <sops>. This composition is
subject to the following:
* Semop performs the composite operation atomically.
Semop succeeds and changes all subject semaphores only
when all individual operations can be performed at a
given time.
Licensed material--property of copyright holder(s) Page 2
semop(2) DG/UX 4.30 semop(2)
* The calling process is suspended due to the first
individual operation in <sops> that requires
suspension.
* When the calling process is suspended, it is registered
as waiting for only one semaphore's value to either
increase or become zero, that semaphore being the
subject semaphore of the individual operation that
suspended the process.
* Neither the individual operations nor the composite
operation are guaranteed to solve the mutual exclusion
livelock problem.
If semop fails, the semaphore set will remain unchanged.
Upon successful completion, the calling process is recorded
as the last process to perform an operation on each
semaphore specified in the array pointed to by <sops> and
the current time is recorded as the most recent time a semop
operation was performed.
ACCESS CONTROL
Alter access to the semaphore set is required to change the
value of a semaphore. Read access is required to wait for a
semaphore value to become zero.
RETURN VALUE
0 Completed successfully.
-1 An error occurred. Errno is set to indicate
the error.
EXCEPTIONS
Errno may be set to one of the following error codes:
EINVAL <Semid> is not a valid semaphore set
identifier.
EINVAL The number of semaphore sets for which the
calling process requests a SEM_UNDO would
exceed the system-imposed limit.
EFBIG <Sem_num> is less than zero or greater than
or equal to the number of semaphores in the
set associated with <semid> for one or more
semaphore operations.
Licensed material--property of copyright holder(s) Page 3
semop(2) DG/UX 4.30 semop(2)
E2BIG <nsops> is greater than the system-imposed
maximum.
EACCES One of the semaphore operations (sem_op) is
non-zero and the caller does not have write
access.
EACCES One of the semaphore operations (sem_op) is
zero and the caller does not have read
access.
EFAULT <sops> is an illegal address.
EAGAIN Semaphore operations would result in
suspension of the caller who has requested
IPC_NOWAIT
ENOSPC The limit on the number of processes
requesting a SEM_UNDO would be exceeded.
ERANGE One of the semaphore operations would cause a
semaphore's value to overflow the system-
imposed limit.
ERANGE One of the semaphore operations would cause a
process's semaphore adjustment value to
overflow the system-imposed limit.
EIDRM <semid> was removed from the system while the
caller was suspended by semop.
EINTR The caller received a signal that was set to
be caught while suspended by semop.
SEE ALSO
exec(2), exit(2), fork(2), intro(2), ipcrm(1), ipcs(1),
semctl(2), semget(2).
Licensed material--property of copyright holder(s) Page 4