CS Electrical And Electronics
@cselectricalandelectronics
All PostsElectronicsOperating SystemWhat Is

What Is A Deadlock In Operating System, How To Prevent Deadlock

Hello guys, welcome back to my blog. In this article, I will discuss what is a deadlock in the operating system, how to prevent deadlock in the operating system, conditions that take place a deadlock in the operating system, etc.

If you have any doubts related to electrical, electronics, and computer science, then ask question. You can also catch me @ Instagram – Chetan Shidling. 

Also, read:

What Is A Deadlock In Operating System

Many processes (now being executed) are running in the background of an operating system. All of these operations are critical to the computer’s operation. It specifies the fundamental unit of labor that the system must carry out. Processes run in sequential order. To perform or complete these procedures, some resources are required. This is done in sequential order.

The procedure starts by requesting a resource. The OS grants the resource if it is available. Otherwise, the procedure will have to be postponed. The resource is released after the process has used it. If a difficulty emerges during the waiting and releasing process, it indicates that a stalemate has occurred.

What is Deadlock?

A deadlock occurs when a process waiting for a resource is unable to execute because that resource is now held by another process and is being used for that process’s execution; as a result, the process is not executed. Furthermore, numerous other processes may be awaiting the delivery of a resource. A condition of impasse is established.

Assume that P1 and P2 are the two processes in question. They have been allotted the resources R1 and R2. So, if P1 requires R2 to finish its execution, but P2 is holding R2, P1 will have to wait. P2 may also be waiting for R1, which P1 holds. As a result, P2 must wait for P1 to release the resource. As a result, a deadlock occurs, and neither process can complete its execution. The system may become unresponsive as the processes become blocked.

A deadlock is a collection of stalled processes, each holding a resource and waiting to obtain another process’s resource.

Condition for Deadlock

Only if all four of the following conditions are met at the same time may a stalemate occur:

01. Mutual Exclusion: At least one resource must be non-shareable under this criterion (non-shareable resources are those that can be used by one process at a time).

02. Hold and wait: This condition indicates that a process is holding at least one resource and is waiting for more.

03. No preemption: Resources cannot be stolen from the process since the process that has them can only release them voluntarily.

04. Circular wait: The collection of processes in this state are waiting for each other in a cyclic pattern. Because the circular wait condition implies the hold and waits for a condition, the above four requirements are not totally independent. We underline that for a deadlock to occur, all four conditions must be met.

A variety of strategies can be used to avoid deadlock situations. Let’s have a look at a few of the approaches.

Methods For Handling Deadlocks:

The following are some of the methods that have been used to solve the problem of deadlocks:

01. Ignoring the Deadlock: It is assumed that no deadlock will ever arise using this strategy. Many operating systems take this strategy, assuming that deadlock will never occur. As a result, the stalemate is ignored by the operating system. This method may be useful for computers that are just used for browsing and routine operations. As a result, while ignoring the deadlock solution can be useful in some situations, it is not ideal for removing the deadlock from the operating system.

02. Deadlock Prevention: As we saw in the previous section if a system meets all four conditions: mutual exclusion, hold and wait, no preemption, and circular wait, then deadlock occurs. The major goal of the deadlock prevention method is to break any one of the four conditions since if any one of them is broken, the problem of deadlock will never happen. Although the concept behind this method is simple, the physical implementation of this method in the system can be complicated.

03. Avoiding the Deadlock: The operating system uses this mechanism to determine if the system is in a safe or dangerous state. This approach examines every action taken by the operating system. Any process will continue to run until the system has reached a safe condition. The operating system must take a step back once the system has entered an unsafe condition.

Essentially, the operating system uses this mechanism to keep a watch on each allocation and ensure that it does not trigger a system-wide stalemate.

04. Deadlock detection and recovery: The stalemate is initially discovered utilizing some resource-allocation graph methods in this method. This graph is mostly used to illustrate resource allocations to distinct processes. After a deadlock has been detected, a variety of ways can be utilized to break the stalemate.

Preemption is one method in which a resource owned by one operation is transferred to another. The second method is to roll back because the operating system maintains a record of the process state and may make a processed roll back to its prior state, eliminating a stalemate. The final option for breaking the impasse is to kill one or more processes.

To sum up, Operating system deadlocks are a typical occurrence. While some operating systems ignore them like the ostrich, others may handle them differently. If a stalemate occurs, the system may save the status of the processes and restore the system to the previous checkpoint. It will re-allocate resources so that no more deadlocks occur.

I hope this article “What Is A Deadlock In Operating System” may help you all a lot. Thank you for reading “What Is A Deadlock In Operating System“.

Also, read:

Share Now

Mayank Rochani

Content Writer

Leave a Reply

Your email address will not be published. Required fields are marked *