The necessary condition to occur deadlock, mutual exclusion, no preemption in operating systems
A process P1 holding some resources and waiting for some another resource that is held by some another Process P2. Similarly, P2 has some resources and waiting for some resources held by P1. In this condition, both processes are deadlocked. None of them can complete their execution.
What are the four necessary conditions to occur deadlock?
If these four conditions occur simultaneously, then it is the deadlock.
If a resource is shareable and can be accessed by more than one process at the same time. Then it leads to a deadlock.
Hold and wait
If one process holding a resource and waiting for another resource that is held by another process. Then it leads to a deadlock.
If processes are waiting for resources in a circle. For example, P1 is holding Resource R1 and waiting for resource R2. Similarly, P2 holding resource R2 and waiting for resource R1 as represented in figure 1.Then it leads to a deadlock.
If we have set no priority for all processes, then every process demands that it will execute first and utilize the resources. Then it leads to a deadlock.
Examples and Case Studies of deadlock
Observe the Resource allocation graph as mentioned below and tell whether deadlock is occurring or not?
what is starvation in OS?
Starvation means a process is hungry. In funny way, we can say that processes eat resources and if a process needs a resource but unable to get a resource to eat, then we can say that process is under starvation.
Starvation happens if the process requires a resource for execution that it is never allocated to the process, then the process is in starvation. We need to allocate the resources efficiently and smartly to overcome the starvation. Some of the common causes of starvation are mentioned below;
- A lower priority process may wait forever if higher priority processes constantly utilizing the required resource.
- Faulty resource allocation to the processes
- If random selection of processes is used then a non-selected process may wait for a long time.
- If there are not enough resources available to allocate to every process as required.
Solutions of Starvation
Some solutions that can be implemented in a system to handle the problem of starvation are mentioned below;
- Avoid Random selection of processes to overcome the starvation.
- An independent and fair manager can be used for distribution of the resources.
- Aging is the possible solution of starvation. Operating system can increase the priority of a process based on its waiting time in the ready queue.
Difference between starvation and deadlock
I am sharing with you some of the common comparison between starvation and deadlock.
|Basic||Deadlock is a condition where no process can further execute, and get blocked.||Starvation is where low priority processes get blocked due to a high priority process.|
|Arising condition||Mutual exclusion
Hold and wait
|Assigning the priorities to the processes.
Inefficient resource allocation
Inefficient resource management
|Other name||Circular wait is another name of deadlock.||Life lock is another name of starvation.|
|Resources||In deadlocked, requested resources are blocked by other processes having that resources.||In starvation, the requested resources are continuously used by other processes having higher priority.|
|Prevention||Avoiding the following conditions;
hold and wait