


In spooling, when multiple processes request the printer, their jobs ( instructions of the processes that require printer access) are added to the queue in the spooler directory. Spooling: It stands for Simultaneous Peripheral Operations online.Ī Printer has associated memory which can be used as a spooler directory (memory that is used to store files that are to be printed next). It is not possible to eliminate mutual exclusion, as some resources are inherently non-shareable,įor Example: Tape drive, as only one process can access data from a Tape drive at a time.įor other resources like printers, we can use a technique called Spooling. Write operation requires sequential access, so, some processes have to wait while another process is doing a write operation. Shared resources do not cause deadlock but some resources can't be shared among processes, leading to a deadlock.įor Example: read operation on a file can be done simultaneously by multiple processes, but write operation cannot. For unshareable resources, processes require exclusive control of the resources.Ī mutual exclusion means that unshareable resources cannot be accessed simultaneously by processes. Some resources are inherently unshareable, for example, Printers. We will see one by one how we can violate each of them to make safe requests and which is the best approach to prevent deadlock. Deadlock Prevention Techniquesĭeadlock prevention techniques refer to violating any one of the four necessary conditions. Here OS does not need to do any additional tasks as it does in deadlock avoidance by running an algorithm on requests checking for the possibility of deadlock. Some of the requests for resources can lead to deadlock.ĭeadlock prevention is eliminating one of the necessary conditions of deadlock so that only safe requests are made to OS and the possibility of deadlock is excluded before making requests.Īs now requests are made carefully, the operating system can grant all requests safely. When a process runs, it needs resources like CPU cycles, Files, or Peripheral device access.


Deadlock Prevention in Operating SystemĪ process is a set of instructions. In this article, we will learn about deadlock prevention in OS.ĭeadlock prevention is a set of methods used to ensure that all requests are safe, by eliminating at least one of the four necessary conditions for deadlock. Deadlock prevention and deadlock avoidance are carried out before deadlock occurs. If there is already traffic on road, then a car coming from the opposite direction can cause blockage.ĭeadlock detection & recovery: OS detects deadlock by regularly checking the system state, and recovers to a safe state using recovery techniques.Įxample: Unblocking the road by backing cars from one side. Any request that may result in a deadlock is not granted.Įxample: Checking each car and not allowing any car that can block the road. Deadlock happens only when all four conditions occur simultaneously for unshareable single instance resources.ĭeadlock prevention: The possibility of deadlock is excluded before making requests, by eliminating one of the necessary conditions for deadlock.Įxample: Only allowing traffic from one direction, will exclude the possibility of blocking the road.ĭeadlock avoidance: Operating system runs an algorithm on requests to check for a safe state. There are four necessary conditions for deadlock. We can understand this from the above example, two cars require the road at the same time but it cannot be shared as it is one way. A deadlock in the operating system is a situation of indefinite blocking of one or more processes that compete for resources.ĭeadlock involves resources needed by two or more processes at the same time that cannot be shared.
