Deadlocks in Operating systems | DBMS

0
94

INTRODUCTION

A process needs exclusive access to several resources. Often devices such as scanners, DVD recorders, printers, and tape drives are connected to the network as shared resources, available to any user on any machine. Now, unfortunately, all these devices can be reserved remotely, then this situation is also called as deadlock. A resource can be a computer hardware device or a piece of information. Generally, a computer has many resources that can be acquired.

Resources in Deadlock

There are the following types of resources.

  • Preemptable Resources
  • Nonpreemptable Resources

Preemptable Resources

A preemptable resource is the one that can be taken away from the process owning it with no ill effects.Memory is an example of a preemptable resource.

Nonpreemptable Resources

Without causing the computation to fail, a nonpreemptable resource is the one that can be taken away from its current owner. For example CD.

Condition for deadlock

ConditionDescription
Mutual exclusion conditionIn mutual exclusion condition, each resources is either currently assigned to exactly one process or is available
Hold and wait conditionIn hold and wait condition, processes currently holding resources granted earlier can request new resources
No preemption conditionIn no preemption condition, resources previously granted can’t be forcibly taken away from a process. They must be explicitly released by the process holding them
Circular wait conditionIn circular wait condition, there must be a circular chain of two or more processes, each of which is waiting for a resource held by the next member of the chain

Deadlock Detection

Deadlock Detection with One Resource of Each Type

In this case, there is only one resource of each type exists. Such type of system might have one plotter, one scanner, one tape drive, and one DVD recorder, but no more than one of each class of resource.

In case if the graph of this system contains one or more cycles, then a deadlock exists. Any process that is part of a cycle is deadlocked. In case if no cycle exists, then the system is not deadlocked.Graph data structure can be used to detect the presence of deadlock

Deadlock Detection with Multiple Resource of Each Type

In this case of deadlock detection, whenever multiple copies of some of the resources exist, a different approach is needed to detect deadlocks.

In this case, present a matrix-based algorithm to detect deadlock between/among more than one process or among n processes, that is P1 through Pn.

Deadlock Recovery

Deadlock Recovery through Preemption

The ability to take a resource away from a process, have another process using it, and then give it back without the process noticing. Deadlock recovery through preemption is too difficult or sometimes impossible.

Deadlock Recovery through RollBack

In this case of deadlock recovery through rollback, whenever a deadlock is detected, it is easy to see which resources are needed. To do the recovery of deadlock, a process that owns a needed resource is rolled back to a point in time before it acquired some other resource just by starting one of its earlier checkpoints.

Deadlock Recovery through Killing Processes

This method of deadlock recovery through killing processes is the simplest way of deadlock recovery. Sometimes it is best to kill a process that can be returned from the beginning with no ill effects.

FAQ’s

Example of deadlock?

Suppose there are multiple clients want to access database table (resource) at the server side. But the server can not give access to all the clients to modify data at the same time. If the server allows multiple clients to modify data in the database table at the same time, data violation will occur.

What are Deadlocks handling strategies to avoid deadlock.

Prevention of Deadlock
Avoidance of Deadlock
Deadlock Detection and Recover
Deadlock Ignorance