Tunable Kernel Parameters

Table Of Contents
Interprocess Communication (IPC) Subsystem
Overview of Semaphore Operations
Chapter 5
37
Overview of Semaphore Operations
System V IPC semaphores are used mainly to keep processes properly synchronized to
prevent collisions when accessing shared data structures. Their use in software tends to
be complex, so many programmers use alternate means of control where practical.
See “Semaphore Parameter Summary” on page 32 for the list of parameters.
Semaphore Operations
The semget() system call allocates an array containing a specified number of
semaphores (see semget (2)). Assigning an array with only one semaphore in the set is
usually the most sensible for keeping programs reasonably simple. Subsequent
semaphore operations are performed atomically on the entire array; individual
semaphores in the array are manipulated by an array of semaphore operations (see
semop (2)). semctl() is used to ascertain or change a semaphore's permissions, change
time, or owner (see semctl (2)).
Semaphores are typically incremented by a process to block other processes while it is
performing a critical operation or using a shared resource. When finished, it decrements
the value, allowing blocked processes to then access the resource. Semaphores can be
configured as binary semaphores which have only two values: 0 and 1, or they can serve
as general semaphores (or counters) where one process increments the semaphore and
one or more cooperating processes decrement it. To prevent undetectable overflow
conditions, the kernel imposes a maximum value limit beyond which semaphores cannot
be incremented. This limit, defined by the semvmx kernel parameter, must not exceed the
maximum value of 65535. Semaphores are not allowed to have negative (less than zero)
values.
Semaphore Undo Operations
It may occasionally be necessary — when errors occur, a process must abort, a process
dies, etc. — to change one or more semaphores to a new or previous value. This is called
undoing a semaphore. Since the value of any semaphore when such conditions occur is
unpredictable, the system enforces a limit on how much the value of a semaphore can
change any undo operation. This limit is defined by the semaem kernel parameter.
For more information about System V IPC semaphore operation, consult an advanced
UNIX programming text such as Advanced UNIX Programming by Marc J. Rochkind,
Prentice-Hall, Inc., ISBN 0-13-011800-1.
Semaphore Limits
Configurable kernel parameters are available to limit the number of sets of semaphores
that can exist simultaneously on the system and the total number of individual
semaphores available to users that can exist simultaneously on the system. The number
of semaphores that can exist in a set is not configurable. It is fixed at the POSIX
standard value, 500.