DEADLOCKS Flashcards
What is a deadlock?
A deadlock is a situation in which two computer programs sharing the same resource are effectively preventing each other from accessing the resource, resulting in both programs ceasing to function.
Illustrate the occurrence of a deadlock
*See notes for illustration
Differentiate between starvation and deadlock
Research babe ;)
What are the conditions that are necessary for a Deadlock to occur
- Mutual Exclusion- A resource can only be shared in mutually exclusive manner. It implies, if two process cannot use the same resource at the same time.
- Hold and Wait- A process waits for some resources while holding another resource at the same time.
- No preemption- The process which once scheduled will be executed till the completion. No other process can be scheduled by the scheduler meanwhile.
- Circular Wait- All the processes must be waiting for the resources in a cyclic manner so that the last process is waiting for the resource which is being held by the first process.
What are some strategies for handling deadlock
- Deadlock ignorance
2.Deadlock prevention
3.Deadlock avoidance
4.Deadlock detection and recovery
Describe deadlock ignorance
- Most widely used approach.
-Used mainly for a single end user system where the user uses the system only for browsing and all other normal stuff.
-In this approach, the Operating system assumes that deadlock never occurs. It simply ignores deadlock. - There is always a tradeoff between Correctness and performance.
The performance of the system decreases if it uses deadlock handling mechanism all the time if deadlock
happens 1 out of 100 times . - In these types of systems, the user has to simply restart the computer in the case of deadlock. Windows and Linux are mainly using this approach.
Describe deadlock prevention
- Deadlock happens only when Mutual Exclusion, hold and wait, No preemption and circular wait holds
simultaneously.
-If it is possible to violate one of the four conditions at any time then the deadlock can never occur
in the system. - The idea behind the approach is very simple that we have to fail one of the four conditions but there can be a big argument on its physical implementation in the system.
Describe deadlock avoidance
- In deadlock avoidance, the operating system checks whether the system is in safe state or in unsafe state at every step which the operating system performs.
-The process continues until the system is in safe state. Once the system moves to unsafe state, the OS has to backtrack one step. - In simple words, The OS reviews each allocation so that the allocation doesn’t cause the deadlock in the system.
Describe deadlock detection and recovery
This approach let the processes fall in deadlock and then periodically check whether deadlock occur in the system or not. If it occurs then it applies some of the recovery methods to the system to get rid of deadlock.
Describe how to prevent mutual exclusion and give an example
- Mutual section from the resource point of view is the fact that a resource can never be used by more than one process simultaneously which is fair enough but that is the main reason behind the deadlock.
-The resource is thus made to function in a way that is not mutually exclusive
-A good example is the spooling on a printer
What are the issues involved with preventing mutual exclusion specifically spooling
- This cannot be applied to every resource.
- After some point of time, there may arise a race condition between the processes to get space in that spool.
- We cannot force a resource to be used by more than one process at the same time since it will not be fair enough and some serious problems may arise in the performance. Therefore, we cannot violate mutual exclusion for a process practically.
How can one prevent the hold and wait condition?
-Hold and wait condition lies when a process holds a resource and waiting for some other resource to complete its task. Deadlock occurs if more than one process hold and wait in a cyclic order
-To prevent this a process must be assigned all the necessary resources before the execution starts. A process must not wait for any resource once the
execution has been started.
What are the issues involved in preventing hold and wait
- Practically impossible.
- Possibility of getting starved will be increases due to the fact that some process may hold a resource for a very long time.
How can one prevent no preemption
Deadlock arises due to the fact that a process can’t be stopped once it starts. However, if we take the resource away from the process which is causing deadlock then we can prevent deadlock.
What are some of the issues that arise when trying to prevent no preemption
-If we take a resource away which is being used by the process then all the work which it has done till now can become inconsistent.
-Consider a printer is being used by any process. If we take the printer away from that process and assign it to some other process then all the data which has been printed can become inconsistent and ineffective and also the fact that the process can’t start printing again from where it has left which causes performance inefficiency.