Semaphores are IPC mechanism which allow different processes to synchronize their access to certain resources.

Semaphores in Linux

The simplest kind of semaphores is called a binary semaphore and they have two states ( locked or unlocked ).
These act like traffic lights, which allows certain processes to exclusively access certain resources.
When a process wants exclusive access to a resource, example: shared memory, they attempt to lock the semaphore associated with that resource. If the semaphore they are attempting to lock is already locked, the caller is suspended, otherwise they are granted to lock.


When the process completes the task, it unlock the resource and any processes that have attempted to lock that semaphore in the meantime are woken up again to attempt the lock again. This way only one process can have access to the resource at once.


In addition, semaphores can also be used as a signaling mechanism.

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Blog Archive

Powered by Blogger.

- Copyright © 2013 Taqi Shah Blogspot -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -