SYSTEM V SEMAPHORES
This chapter describes System V semaphores. Unlike the IPC mechanisms
described in previous chapters, System V semaphores are not used to transfer data
between processes. Instead, they allow processes to synchronize their actions. One
common use of a semaphore is to synchronize access to a block of shared memory,
in order to prevent one process from accessing the shared memory at the same
time as another process is updating it.
A semaphore is a kernel-maintained integer whose value is restricted to being
greater than or equal to 0. Various operations (i.e., system calls) can be performed
on a semaphore, including the following:
z setting the semaphore to an absolute value;
z adding a number to the current value of the semaphore;
z subtracting a number from the current value of the semaphore; and
z waiting for the semaphore value to be equal to 0.
The last two of these operations may cause the calling process to block. When lower-
ing a semaphore value, the kernel blocks any attempt to decrease the value below 0.
Similarly, waiting for a semaphore to equal 0 blocks the calling process if the sema-
phore value is not currently 0. In both cases, the calling process remains blocked
until some other process alters the semaphore to a value that allows the operation
to proceed, at which point the kernel wakes the blocked process. Figure 47-1 shows