File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / man / man2 / semop.2i
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:26:36 2019 UTC (7 years ago) by root
Branches: bsd, MAIN
CVS tags: v121, HEAD
Power 6/32 Unix version 1.21

.TH SEMOP 2
.SH NAME
semop \- semaphore operations
.SH SYNOPSIS
.B #include <sys/types.h>
.br
.B #include <sys/ipc.h>
.br
.B #include <sys/sem.h>
.PP
.nf
.B int semop (semid, sops, nsops)
.B int semid;
.B struct sembuf **sops;
.B int nsops;
.fi
.SH DESCRIPTION
.I Semop
is used to automatically perform 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
short	sem_num;	/\(** semaphore number \(**/
short	sem_op;	/\(** semaphore operation \(**/
short	sem_flg;	/\(** operation flags \(**/
.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:
.PP
.RS 8
If
.I sem_op
is a negative integer, one of the following will occur:
.SM
\%{ALTER}
.IP
If semval (see
.IR intro (2))
is greater than or equal to the absolute value of
.IR sem_op ,
the absolute value of
.I sem_op
is subtracted from semval.
Also, if
.RI ( sem_flg " &"
.SM
.BR SEM_UNDO\*S )
is ``true'', the absolute value of
.I sem_op
is added to the calling process's semadj value (see
.IR exit (2))
for the specified semaphore.
.IP
If semval is less than the absolute value of
.I sem_op
and
.RI ( sem_flg " &"
.SM
.BR IPC_NOWAIT\*S )
is ``true'',
.I semop
returns immediately.
.IP
If semval is less than the absolute value of
.I sem_op
and
.RI ( sem_flg " &"
.SM
.BR IPC_NOWAIT\*S )
is ``false'',
.I semop
increments the semncnt associated with the specified semaphore
and suspend execution of the calling process 
until one of the following conditions occurs.
.RS 8
.PP
Semval becomes greater than or equal to the absolute value of
.IR sem_op .
When this occurs, the value of semncnt associated with the specified
semaphore is decremented, the absolute value of
.I sem_op
is subtracted from semval and, if
.RI ( sem_flg " &"
.SM
.BR SEM_UNDO\*S )
is ``true'', the absolute value of
.I sem_op
is added to the calling process's semadj value for the specified semaphore.
.PP
The semid for which the calling process is awaiting action
is removed from the system (see
.IR semctl (2)).
When this occurs,
.I errno
is set equal to
.SM
EIDRM\*S,
and a value of \-1 is returned.
.PP
The calling process receives a signal that is to be caught.
When this occurs, the value of semncnt associated with the specified
semaphore is decremented,
and the calling process resumes execution in the manner prescribed in
.IR signal (2).
.RE
.PP
If
.I sem_op
is a positive integer, the value of
.I sem_op
is added to semval
and, if
.RI ( sem_flg " &"
.SM
.BR SEM_UNDO\*S )
is ``true'', the value of
.I sem_op
is subtracted from the calling process's semadj value for the specified
semaphore.
.SM
\%{ALTER}
.PP
If
.I sem_op
is zero,
one of the following occurs:
.SM
\%{READ}
.IP
If semval is zero,
.I semop
returns immediately.
.IP
If semval is not equal to zero and
.RI ( sem_flg " &"
.SM
.BR IPC_NOWAIT\*S )
is ``true'',
.I semop
returns immediately.
.IP
If semval is not equal to zero and
.RI ( sem_flg " &"
.SM
.BR IPC_NOWAIT\*S )
is ``false'',
.I semop
increments the semzcnt associated with the specified semaphore
and suspends execution of the calling process until
one of the following occurs:
.RS 8
.PP
Semval becomes zero, at which time the value of semzcnt associated with the
specified semaphore is decremented.
.PP
The semid for which the calling process is awaiting action
is removed from the system.
When this occurs,
.I errno
is set equal to
.SM
EIDRM\*S,
and a value of \-1 is returned.
.PP
The calling process receives a signal that is to be caught.
When this occurs, the value of semzcnt associated with the specified
semaphore is decremented,
and the calling process resumes execution in the manner prescribed in
.IR signal (2).
.RE
.RE
.PP
.I Semop
fails if one or more of the following are true for any of the semaphore
operations specified by
.IR sops :
.TP 15
.TP
\s-1\%[EINVAL]\s+1
.I Semid
is not a valid semaphore identifier.
.TP
\s-1\%[EFBIG]\s+1
.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
\s-1\%[E2BIG]\s+1
.I Nsops
is greater than the system-imposed maximum.
.TP
\s-1\%[EACCES]\s+1
Operation permission is denied to the calling process (see
.IR intro (2)).
.TP
\s-1\%[EAGAIN]\s+1
The operation would result in suspension of the calling process but
.RI ( sem_flg " &"
.SM
.BR IPC_NOWAIT\*S )
is ``true''.
.TP
\s-1\%[ENOSPC]\s+1
The limit on the number of individual  processes requesting an
.SM
.B SEM_UNDO
would be exceeded.
.TP
\s-1\%[EINVAL]\s+1
The number of individual semaphores for which the calling process
requests a
.SM
.B SEM_UNDO
would exceed the limit.
.TP
\s-1\%[ERANGE]\s+1
An operation would cause a semval to overflow the system-imposed limit.
.TP
\s-1\%[ERANGE]\s+1
An operation would cause a semadj value to overflow the
system-imposed limit.
.TP
\s-1\%[EFAULT]\s+1
.I Sops
points to an illegal address.
.PP
Upon successful completion, the value of sempid
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 RETURN VALUE
.RI If " semop
returns due to the receipt of a signal, a value of \-1 is returned to the
calling process and
.I errno
is set to
.SM
\%EINTR\*S.
If it returns due to the removal of a
.I semid
from the system, a value of \-1 is returned and
.I errno
is set to
.SM
\%EIDRM\*S.
.PP
Upon successful completion, the value of semval at the time of the call for the
last operation in the array pointed to by
.I sops
is returned.
Otherwise, a value of \-1 is returned and
.I errno
is set to indicate the error.
.SH SEE ALSO
exec(2), exit(2), fork(2), intro(2), semctl(2), semget(2).
.\"	@(#)semop.2	6.2 of 9/6/83

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.