Semaphore is a means of signalling using pairs of flags. Different flag positions stand for different letters and numbers. Semaphore signals are useful when the signaller is within sight of the receiver of the message but too far away to call out. It was widely used between ships sailing near each other in the days before ship-to-ship radio.

In programming, especially in UNIX systems, semaphores are a technique for coordinating or synchronizing activities in which multiple processes compete for the same operating system resources. A semaphore is a value in a designated place in operating system (or Kernel) storage that each process can check and then change. Depending on the value that is found, the process can use the resource or will find that it is already in use and must wait for some period before trying again. Semaphores can be binary (0 or 1) or can have additional values. Typically, a process using semaphores checks the value and then, if it using the resource, changes the value to reflect this so that subsequent semaphore users will know to wait.

Semaphores are commonly used for two purposes: to share a common memory space and to share access to files. Semaphores are one of the techniques for interprocess communication (IPC). The C programming language provides a set of interfaces or “functions” for managing semaphores.

Picture Credit : Google