
- OS - Home
- OS - Needs
- OS - Overview
- OS - History
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- OS - TAT & WAT
- OS Processes
- OS - Processes
- OS - Process Scheduling
- OS - Scheduling Algorithms
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithms
- HRRN Scheduling Algorithms
- Priority Scheduling Algorithms
- Multilevel Queue Scheduling
- Context Switching
- Operations on Processes
- Lottery Process Scheduling
- Predicting Burst Time SJF Scheduling
- Race Condition Vulnerability
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Process Control Block
- Inter Process Communication
- Preemptive and Non-Preemptive Scheduling
- Operating System - Deadlock
- Introduction to Deadlock in Operating System
- Conditions for Deadlock in Operating System
- OS Synchronization
- Operating System - Process Synchronization
- Operating System - Critical Section
- Operating System - Semaphores
- Operating System - Counting Semaphores
- Operating System - Mutex
- Operating System - Turn Variable in Process Synchronization
- Operating System - Bounded Buffer Problem
- Operating System - Reader Writer Locks in Process Synchronization
- Operating System - Test Set Lock in Process Synchronization
- Operating System - Peterson Solution in Process Synchronization
- Operating System - Monitors in Process Synchronization
- Operating System - Sleep and Wake in Process Synchronization
- OS Memory Management
- OS - Memory Management
- OS - Virtual Memory
- OS Storage Management
- File Systems in Operating System
- Linked Index Allocation in Operating System
- Indexed Allocation in Operating System
- Structures of Directory in Operating System
- File Attributes in Operating System
- Operating System - Page Replacement
- Operating Systems - Thrashing
- Optimal Page Replacement Algorithm
- Operating System - Types
- Types of Operating System
- Batch Processing Operating System
- Multiprocessing Operating System
- Hybrid Operating System
- Monolithic Operating System
- Zephyr Operating System
- Nix Operating System
- Blackberry Operating System
- Garuda Operating System
- Tails Operating System
- Clustered Operating System
- Haiku Operating System
- AIX Operating System
- Solus Operating system
- Tizen Operating System
- Bharat Operating System
- Fire Operating System
- Bliss Operating System
- VxWorks Operating System
- Embedded Operating System
- Single User Operating System
- OS Miscellaneous
- OS - Multi-threading
- OS - I/O Hardware
- OS - I/O Software
- OS - Security
- OS - Linux
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
OS Semaphores Q & A #1
Question: Explain semaphores and write a short note on it.
Answer: Dijkestra proposed a significant technique for managing concurrent processes for complex mutual exclusion problems. He introduced a new synchronization tool called Semaphore.
Semaphores are of two types −
Binary semaphore
Counting semaphore
Binary semaphore can take the value 0 & 1 only. Counting semaphore can take nonnegative integer values.
Two standard operations, wait and signal are defined on the semaphore. Entry to the critical section is controlled by the wait operation and exit from a critical region is taken care by signal operation. The wait, signal operations are also called P and V operations. The manipulation of semaphore (S) takes place as following:
The wait command P(S) decrements the semaphore value by 1. If the resulting value becomes negative then P command is delayed until the condition is satisfied.
The V(S) i.e. signals operation increments the semaphore value by 1.
Mutual exclusion on the semaphore is enforced within P(S) and V(S). If a number of processes attempt P(S) simultaneously, only one process will be allowed to proceed & the other processes will be waiting.These operations are defined as under −
P(S) or wait(S): If S > 0 then Set S to S-1 Else Block the calling process (i.e. Wait on S) V(S) or signal(S): If any processes are waiting on S Start one of these processes Else Set S to S+1
The semaphore operation are implemented as operating system services and so wait and signal are atomic in nature i.e. once started, execution of these operations cannot be interrupted.
Thus semaphore is a simple yet powerful mechanism to ensure mutual exclusion among concurrent processes.