in this post, we are going to study about process synchronization in os | cooperating process | critical section problem | semaphore. before starting to process synchronization we must know about cooperating process.
what is cooperating process:-
the cooperating process is the process that can affect or be affected by other processes that are executing in the system. suppose there is n process that shares logical address space or data through file or message in this case we need process synchronization to solve the problem of starvation.
Process synchronization in os
Process synchronization in os share system resources by processes so that concurrent access to shared data is handled and the chance of inconsistency can be minimized.
Process Synchronization was introduced to solve the problems that arise while multiple processes execute at the same time or concurrent access the resource.
critical section problem
the critical section is a code segment that accesses shared variable and has to be executed as an atomic action, only one process must be executing its critical section at a given time.
Solution to Critical Section Problem
A solution to the critical section problem must satisfy the following three conditions :
Out of a group of cooperating processes, if one process is executing in the critical section, then no other process is allowed to execute in the critical section.
If no process is executing in its critical section and some process wants to enter the critical section then only those processes that are not executing in the remainder section can participate.
After a process makes a request for getting into its critical section, there is a limit on the number of times that other processes are allowed to enter their critical section.So after the limit is reached, the system must grant the process permission to get into its critical section.
Peterson’s Solution is a software-based solution which ensures mutual exclusion for one resource its preserves all three conditions :
- only one process can access the critical section at any time.
- a process outside the critical section does not block other processes from entering the critical section.
- every process gets a fair chance because of the limit the number of times that other processes are allowed to enter their critical section.
it is a synchronization tool and used for a process synchronization.
it is an integer variable, that apart from initialization is accessed only through to standard atomic operation
modification to the integer value of the semaphore in the wait and signal operation must be executed indivisibly. only one process can modify the same semaphore value at a time.
There are two types of semaphores :
- Binary Semaphores
2. Counting Semaphores
- Binary Semaphores:- it can only be either 0 or 1.it is also known as mutex locks. All the processes can share the same mutex semaphore and initialized it to 1.until the lock becomes 0 processes have to wait. Then, the process can make the mutex semaphore 1 and start its critical section. When it completes its critical section, it can reset the value of mutex semaphore to 0 and some other process can enter its critical section.
- Counting Semaphores: Range over the unregistered domain and used to control access to a given resource consisting of the finite number of instance.
Limitations of Semaphores
- busy waiting- when a process is in the critical section, only other process that tries to enter its critical section must loop continuously in its entry code.
- the process may block indefinitely. Such a situation is called Deadlock
you make also like