267 lines
6.3 KiB
Groff
267 lines
6.3 KiB
Groff
'\"macro stdmacro
|
|
.if n .pH g2.semop @(#)semop 41.3 of 5/26/91
|
|
.\" Copyright 1991 UNIX System Laboratories, Inc.
|
|
.\" Copyright 1989, 1990 AT&T
|
|
.nr X
|
|
.if \nX=0 .ds x} semop 2 "" "\&"
|
|
.if \nX=1 .ds x} semop 2 ""
|
|
.if \nX=2 .ds x} semop 2 "" "\&"
|
|
.if \nX=3 .ds x} semop "" "" "\&"
|
|
.TH \*(x}
|
|
.SH NAME
|
|
\f4semop\f1 \- semaphore operations
|
|
.SH SYNOPSIS
|
|
\f4#include <sys/types.h>\f1
|
|
.br
|
|
\f4#include <sys/ipc.h>\f1
|
|
.br
|
|
\f4#include <sys/sem.h>\f1
|
|
.PP
|
|
.nf
|
|
\f4int semop(int semid, struct sembuf \(**sops, size_t nsops); \f1
|
|
.fi
|
|
.SH DESCRIPTION
|
|
\f4semop\fP
|
|
is used to perform atomically an array of semaphore operations on the
|
|
set of semaphores associated with the semaphore identifier specified by
|
|
.IR semid .
|
|
.I sops
|
|
is a pointer to the array of semaphore-operation structures.
|
|
.I nsops
|
|
is the number of such structures in the array.
|
|
The contents of each structure includes the following members:
|
|
.PP
|
|
.RS
|
|
.ta 8n 20n
|
|
.nf
|
|
.ft 4
|
|
short sem_num; /\(** semaphore number \(**/
|
|
short sem_op; /\(** semaphore operation \(**/
|
|
short sem_flg; /\(** operation flags \(**/
|
|
.ft 1
|
|
.fi
|
|
.RE
|
|
.PP
|
|
Each semaphore operation specified by
|
|
.I sem_op
|
|
is performed on the corresponding semaphore specified by
|
|
.IR semid " and " sem_num .
|
|
.PP
|
|
.I sem_op
|
|
specifies one of three semaphore operations as follows,
|
|
depending on whether its value is negative, positive, or zero:
|
|
.PP
|
|
If
|
|
.I sem_op
|
|
is a negative integer, one of the following occurs:
|
|
.SM \%{ALTER}
|
|
.IP "" 5
|
|
If \f4semval\fP [see
|
|
\f4intro\fP(2)]
|
|
is greater than or equal to the absolute value of
|
|
.IR sem_op ,
|
|
the absolute value of
|
|
.I sem_op
|
|
is subtracted from \f4semval\fP.
|
|
Also, if
|
|
(\f2sem_flg\f4&SEM_UNDO\f1)
|
|
is true, the absolute value of
|
|
.I sem_op
|
|
is added to the calling process's \f4semadj\fP value [see
|
|
\f4exit\fP(2)]
|
|
for the specified semaphore.
|
|
.IP
|
|
If \f4semval\fP is less than the absolute value of
|
|
.I sem_op
|
|
and
|
|
(\f2sem_flg\f4&IPC_NOWAIT\f1)
|
|
is true,
|
|
\f4semop\fP
|
|
returns immediately.
|
|
.IP
|
|
If \f4semval\fP is less than the absolute value of
|
|
.I sem_op
|
|
and
|
|
(\f2sem_flg\f4&IPC_NOWAIT\f1)
|
|
is false,
|
|
\f4semop\fP
|
|
increments the \f4semncnt\fP associated with the specified semaphore
|
|
and suspends execution of the calling process
|
|
until one of the following conditions occur.
|
|
.IP "" 8
|
|
\f4semval\fP becomes greater than or equal to the absolute value of
|
|
.IR sem_op .
|
|
When this occurs, the value of \f4semncnt\fP associated with the specified
|
|
semaphore is decremented, the absolute value of
|
|
.I sem_op
|
|
is subtracted from \f4semval\fP and, if
|
|
(\f2sem_flg\f4&SEM_UNDO\f1)
|
|
is true, the absolute value of
|
|
.I sem_op
|
|
is added to the calling process's \f4semadj\fP value for the specified semaphore.
|
|
.IP
|
|
The
|
|
.I semid
|
|
for which the calling process is awaiting action
|
|
is removed from the system [see
|
|
\f4semctl\fP(2)].
|
|
When this occurs,
|
|
\f4errno\fP
|
|
is set equal to
|
|
\f4EIDRM\fP,
|
|
and a value of \-1 is returned.
|
|
.IP
|
|
The calling process receives a signal that is to be caught.
|
|
When this occurs, the value of \f4semncnt\fP associated with the specified
|
|
semaphore is decremented,
|
|
and the calling process resumes execution in the manner prescribed in
|
|
\f4signal\fP(2).
|
|
.PP
|
|
If
|
|
.I sem_op
|
|
is a positive integer, the value of
|
|
.I sem_op
|
|
is added to \f4semval\fP
|
|
and, if
|
|
(\f2sem_flg\f4&SEM_UNDO\f1)
|
|
is true, the value of
|
|
.I sem_op
|
|
is subtracted from the calling process's \f4semadj\fP value for the specified
|
|
semaphore.
|
|
.SM \%{ALTER}
|
|
.PP
|
|
If
|
|
.I sem_op
|
|
is zero,
|
|
one of the following occurs:
|
|
.SM \%{READ}
|
|
.IP "" 5
|
|
If \f4semval\fP is zero,
|
|
\f4semop\fP
|
|
returns immediately.
|
|
.IP
|
|
If \f4semval\fP is not equal to zero and
|
|
(\f2sem_flg\f4&IPC_NOWAIT\f1)
|
|
is true,
|
|
\f4semop\fP
|
|
returns immediately.
|
|
.IP
|
|
If \f4semval\fP is not equal to zero and
|
|
(\f2sem_flg\f4&IPC_NOWAIT\f1)
|
|
is false,
|
|
\f4semop\fP
|
|
increments the \f4semzcnt\fP associated with the specified semaphore
|
|
and suspends execution of the calling process until
|
|
one of the following occurs:
|
|
.IP "" 8
|
|
Semval becomes zero, at which time the value of \f4semzcnt\fP associated with the
|
|
specified semaphore is decremented.
|
|
.IP
|
|
The
|
|
.I semid
|
|
for which the calling process is awaiting action
|
|
is removed from the system.
|
|
When this occurs,
|
|
\f4errno\fP
|
|
is set equal to
|
|
\f4EIDRM\fP,
|
|
and a value of \-1 is returned.
|
|
.IP
|
|
The calling process receives a signal that is to be caught.
|
|
When this occurs, the value of \f4semzcnt\fP associated with the specified
|
|
semaphore is decremented,
|
|
and the calling process resumes execution in the manner prescribed in
|
|
\f4signal\fP(2).
|
|
.PP
|
|
\f4semop\fP
|
|
fails if one or more of the following are true for any of the semaphore
|
|
operations specified by
|
|
.IR sops :
|
|
.TP 15
|
|
\f4EINVAL\fP
|
|
.I semid
|
|
is not a valid semaphore identifier.
|
|
.TP
|
|
\f4EFBIG\fP
|
|
.I sem_num
|
|
is less than zero or greater than or equal to the number of semaphores
|
|
in the set associated with
|
|
.IR semid .
|
|
.TP
|
|
\f4E2BIG\fP
|
|
.I nsops
|
|
is greater than the system-imposed maximum.
|
|
.TP
|
|
\f4EACCES\fP
|
|
Operation permission is denied to the calling process [see
|
|
\f4intro\fP(2)].
|
|
.TP
|
|
\f4EAGAIN\fP
|
|
The operation would result in suspension of the calling process but
|
|
(\f2sem_flg\f4&IPC_NOWAIT\f1)
|
|
is true.
|
|
.TP
|
|
\f4ENOSPC\fP
|
|
The limit on the number of individual processes requesting an
|
|
\f4SEM_UNDO\f1
|
|
would be exceeded.
|
|
.TP
|
|
\f4EINVAL\fP
|
|
The number of individual semaphores for which the calling process
|
|
requests a
|
|
\f4SEM_UNDO\f1
|
|
would exceed the limit.
|
|
.TP
|
|
\f4ERANGE\fP
|
|
An operation would cause a \f4semval\fP to overflow the system-imposed limit.
|
|
.TP
|
|
\f4ERANGE\fP
|
|
An operation would cause a \f4semadj\fP value to overflow the
|
|
system-imposed limit.
|
|
.TP
|
|
\f4EFAULT\fP
|
|
.I sops
|
|
points to an illegal address.
|
|
.TP
|
|
\f4EIDRM\fP
|
|
A
|
|
.I semid
|
|
referenced by the call was removed from the system.
|
|
.PP
|
|
Other errors which can occur on \f4semop\fP are:
|
|
.TP 15
|
|
\f4EINTR\fP
|
|
\f4semop\fP(2) was interrupted by a signal.
|
|
.PP
|
|
Upon successful completion, the value of \f4sempid\fP
|
|
for each semaphore specified in the array pointed to by
|
|
.I sops
|
|
is set equal to the process
|
|
.SM ID
|
|
of the calling process.
|
|
.SH SEE ALSO
|
|
\f4intro\fP(2),
|
|
\f4exec\fP(2), \f4exit\fP(2), \f4fork\fP(2),
|
|
\f4semctl\fP(2), \f4semget\fP(2).
|
|
.SH DIAGNOSTICS
|
|
.RI If " semop"
|
|
returns due to the receipt of a signal, a value of \-1 is returned to the
|
|
calling process and
|
|
\f4errno\fP
|
|
is set to
|
|
\f4EINTR\fP.
|
|
If it returns due to the removal of a
|
|
.I semid
|
|
from the system, a value of \-1 is returned and
|
|
\f4errno\fP
|
|
is set to
|
|
\f4EIDRM\fP.
|
|
.PP
|
|
Upon successful completion, a value of zero
|
|
is returned.
|
|
Otherwise, a value of \-1 is returned and
|
|
\f4errno\fP
|
|
is set to indicate the error.
|
|
.\" @(#)semop.2 6.2 of 9/6/83
|
|
.Ee
|