Deadlock is a situation everyone wants to avoid!
Whether it is your real-life or computer systems, no one wants to get stuck in a deadlock. Deadlock is simply a situation where you can not do anything further and at the same time, you will not be able to undo your actions.
When it comes to operating systems, a deadlock occurs when two systems are using the same resources and interrupting each other’s workflow. For example, if one process is using a printer and the other process is using a scanner. Now, if the third process requires both printer and scanner, it will not be executed until the other two are done. So, the third process will be in a deadlock state.
If a system fails to implement a deadlock prevention or avoidance algorithm, there is a high chance that the system will encounter a deadlock.
In this case, either an algorithm is implemented to check if the system has encountered a deadlock or not using a deadlock detection algorithm or you can simply implement an algorithm to recover from the deadlock.
Well, here, we are considering the first case and will discuss in detail the deadlock detection algorithm.
An Introduction To Deadlock Detection Algorithm
To detect and avoid deadlock in an operating system, Banker’s algorithm is used. This algorithm allocates all the resources to every system safely and ensures that there is no condition of deadlock.
The S-state in the algorithm checks all the possible tests before allocating any resource to the running process. It simplifies the process in which the operating system shares its resources between the processes running on the system.
Are you wondering why the algorithm is called Banker’s algorithm and simply not a deadlock avoidance algorithm?
The name has been given because the process has similarities with how bank grants loan to people. Before sanctioning the loan to anyone, the system analyses the background and available resources to decide if the loan should be sanctioned or not. This streamlines the whole process of the bank and allows the bank to allocate its resources wisely.
Banker’s algorithm works in the same way and hence the name.
How Does Deadlock Detection Algorithm Work?
Let’s understand the working of the deadlock detection algorithm with a real-life example:
Comments