.\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
.\"
+.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
.\"
.\" Modified 1996-10-22, Eric S. Raymond <esr@thyrsus.com>
.\" Modified 2002-01-08, Michael Kerrisk <mtk.manpages@gmail.com>
.\" 2005-04-08, mtk, Noted kernel version numbers for semtimedop()
.\" 2007-07-09, mtk, Added an EXAMPLE code segment.
.\"
-.TH SEMOP 2 2008-10-04 "Linux" "Linux Programmer's Manual"
+.TH SEMOP 2 2013-04-17 "Linux" "Linux Programmer's Manual"
.SH NAME
-semop, semtimedop \- semaphore operations
+semop, semtimedop \- System V semaphore operations
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.BR semtimedop ():
_GNU_SOURCE
.SH DESCRIPTION
-Each semaphore in a semaphore set has the following associated values:
+Each semaphore in a System V semaphore set
+has the following associated values:
.sp
.in +4n
.nf
unsigned short semval; /* semaphore value */
unsigned short semzcnt; /* # waiting for zero */
unsigned short semncnt; /* # waiting for increase */
-pid_t sempid; /* process that did last op */
+pid_t sempid; /* ID of process that did last op */
.sp
.in -4n
.fi
.RI ( semval ).
Furthermore, if
.B SEM_UNDO
-is specified for this operation, the system updates the process undo count
+is specified for this operation, the system subtracts the value
+.I sem_op
+from the semaphore adjustment
.RI ( semadj )
-for this semaphore.
-This operation can always proceed\(emit never forces a process to wait.
+value for this semaphore.
+This operation can always proceed\(emit never forces a thread to wait.
The calling process must have alter permission on the semaphore set.
.PP
If
is performed).
Otherwise
.I semzcnt
-(the count of processes waiting until this semaphore's value becomes zero)
-is incremented by one and the process sleeps until
+(the count of threads waiting until this semaphore's value becomes zero)
+is incremented by one and the thread sleeps until
one of the following occurs:
.IP \(bu 3
.I semval
set to
.BR EIDRM .
.IP \(bu
-The calling process catches a signal:
+The calling thread catches a signal:
the value of
.I semzcnt
is decremented and
.IR semval ,
and, if
.B SEM_UNDO
-is specified for this operation, the system updates the process undo count
+is specified for this operation, the system adds the absolute value of
+.I sem_op
+to the semaphore adjustment
.RI ( semadj )
-for this semaphore.
+value for this semaphore.
If the absolute value of
.I sem_op
is greater than
is performed).
Otherwise
.I semncnt
-(the counter of processes waiting for this semaphore's value to increase)
-is incremented by one and the process sleeps until
+(the counter of threads waiting for this semaphore's value to increase)
+is incremented by one and the thread sleeps until
one of the following occurs:
.IP \(bu 3
.I semval
becomes greater than or equal to the absolute value of
-.IR sem_op ,
-at which time the value of
-.I semncnt
-is decremented, the absolute value of
-.I sem_op
-is subtracted from
-.I semval
-and, if
-.B SEM_UNDO
-is specified for this operation, the system updates the process undo count
-.RI ( semadj )
-for this semaphore.
+.IR sem_op :
+the operation now proceeds, as described above.
.IP \(bu
The semaphore set is removed from the system:
.BR semop ()
set to
.BR EIDRM .
.IP \(bu
-The calling process catches a signal:
+The calling thread catches a signal:
the value of
.I semncnt
is decremented and
.I sempid
value for each semaphore specified in the array pointed to by
.I sops
-is set to the process ID of the calling process.
+is set to the caller's process ID.
In addition, the
.I sem_otime
.\" and
.BR semtimedop ()
behaves identically to
.BR semop ()
-except that in those cases were the calling process would sleep,
+except that in those cases where the calling thread would sleep,
the duration of that sleep is limited by the amount of elapsed
time specified by the
.I timespec
structure whose address is passed in the
.I timeout
argument.
+(This sleep interval will be rounded up to the system clock granularity,
+and kernel scheduling delays mean that the interval
+may overrun by a small amount.)
If the specified time limit has been reached,
.BR semtimedop ()
fails with
.BR semtimedop ()
behaves exactly like
.BR semop ().
-.SH "RETURN VALUE"
-If successful
+.SH RETURN VALUE
+If successful,
.BR semop ()
and
.BR semtimedop ()
The semaphore set was removed.
.TP
.B EINTR
-While blocked in this system call, the process caught a signal; see
+While blocked in this system call, the thread caught a signal; see
.BR signal (7).
.TP
.B EINVAL
Glibc support for
.BR semtimedop ()
first appeared in version 2.3.3.
-.SH "CONFORMING TO"
+.SH CONFORMING TO
SVr4, POSIX.1-2001.
.\" SVr4 documents additional error conditions EINVAL, EFBIG, ENOSPC.
.SH NOTES
+The inclusion of
+.I <sys/types.h>
+and
+.I <sys/ipc.h>
+isn't required on Linux or by any version of POSIX.
+However,
+some old implementations required the inclusion of these header files,
+and the SVID also documented their inclusion.
+Applications intended to be portable to such old systems may need
+to include these header files.
+.\" Like Linux, the FreeBSD man pages still document
+.\" the inclusion of these header files.
+
The
.I sem_undo
structures of a process aren't inherited by the child produced by
regardless of the setting of the
.B SA_RESTART
flag when establishing a signal handler.
-.PP
-.I semadj
-is a per-process integer which is simply the (negative) count
-of all semaphore operations performed specifying the
+
+A semaphore adjustment
+.RI ( semadj )
+value is a per-process, per-semaphore integer that is the negated sum
+of all operations performed on a semaphore specifying the
.B SEM_UNDO
flag.
+Each process has a list of
+.I semadj
+values\(emone value for each semaphore on which it has operated using
+.BR SEM_UNDO .
+When a process terminates, each of its per-semaphore
+.I semadj
+values is added to the corresponding semaphore,
+thus undoing the effect of that process's operations on the semaphore
+(but see BUGS below).
When a semaphore's value is directly set using the
.B SETVAL
or
termination to proceed immediately.
In kernels 2.6.x, x <= 10, there is a bug that in some circumstances
-prevents a process that is waiting for a semaphore value to become
+prevents a thread that is waiting for a semaphore value to become
zero from being woken up when the value does actually become zero.
This bug is fixed in kernel 2.6.11.
.\" The bug report:
exit(EXIT_FAILURE);
}
.fi
-.SH "SEE ALSO"
+.SH SEE ALSO
+.BR clone (2),
.BR semctl (2),
.BR semget (2),
.BR sigaction (2),
.BR sem_overview (7),
.BR svipc (7),
.BR time (7)
+.SH COLOPHON
+This page is part of release 3.65 of the Linux
+.I man-pages
+project.
+A description of the project,
+and information about reporting bugs,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.