

Second condition: The second condition for the occurrence of a deadlock is hold and wait. Again, when a process writes data to a file, it needs to lock the file in an exclusive mode.Ģ. e.g., Two processes can't simultaneously share a scanner. Some resources can't be shared by multiple processes.


The operating system can allow the locking of that file in a shareable mode by the two processes simultaneously. e.g., Consider two processes that need to read data from a file. An operating system can avoid blocking of resources by locking the resources in a shareable mode, if feasible. The mutual exclusion condition indicates locking of resources in exclusion, also known as non-shareable mode, which leads to blocking of resources.

We have known that there are four conditions to be satisfied for the occurrence of a deadlock in os.īelow is a brief discussion about the deadlock prevention conditions: 1. No pre-emption condition is violated and deadlock in os does not occur. Deadlock prevention techniques do not utilize resource properly.Īn operating system adopting the deadlock prevention technique allows resources to be pre-empted from a blocked process. It denies at least one of the conditions required for the occurrence of a deadlock. Deadlock Prevention: Deadlock prevention techniques allocate resources in such a manner that at least one of the four necessary conditions of deadlock cannot occur. Deadlock Prevention? How we use this prevention in the operating system? Deadlock in OS Ans. The P 1 process is waiting for a resource that has been exclusively acquired by the process P 2, the process P 2 is waiting for a resource, which is held exclusively by the process P 3 and the P 3 process is waiting for a resource which has been acquired exclusively by the process P 1. The concept of no pre-emption denotes the operating system cannot revoke the resource R 1 from the process P 1 forcefully.Ī closed chain or a circular relationship exists among the processes involved in a deadlock.Į.g., There are three processes P 1, P 2, and P 3. Processes do not release the resources allotted to them voluntarily without utilizing the resources.Į.g., The process P 1 holds the resource R 1 exclusively and waits for resource R 2 which is locked by the process P 2 in the exclusive mode. The processes involved in a deadlock acquire at least one resource in exclusive mode and wait for at least another resource that has been acquired by another resources in the exclusive mode. In other words, the concept of mutual exclusion depicts that a resource can be utilized by one process at a time. This means no other process can acquire the resource R. One or more resources are acquired in an exclusive mode.Į.g., A process P 1 locks the resource R in the exclusive mode. Conditions for Deadlock: There are four conditions that cause the occurrence of deadlock in os which are as follows: Give the four conditions that causes deadlock in OS? Deadlock Prevention? Ans. On the other hand, when a deadlock situation arises, the processes never complete their execution. The above-mentioned procedure occurs in the situation, when there is no deadlock. When the resource is not required, the process releases it, so that the operating system can allocate the resource to any other process. After acquiring the resource, the process utilizes it to perform a specific task.Į.g., In case of scanner usage, a process has to hold a lock on the resource and then use it to scan a document. If a computer has two printers, no process can request three or more printers. A process can also request for multiple numbers of instances of a resource but it must be less than the total number of resources available. If all the instances of the requested resource are engaged with other processes, the process waits until an instance of the requested resource becomes free. But if the process locks a resource in an exclusive mode, no other process is allowed to access that resource. If a process locks a resource in a shareable mode, the operating system allows other processes to access that resource. If the resource is available, the operating system allocates the resource to that process.Ī process can acquire and lock a resource in an exclusive or shareable mode. First, a process requests the operating system to allocate a resource. Deadlock in OS: A specific sequence of tasks are performed when a process tries to access a resource. Deadlock Management? or Deadlock in OS? Ans.
