In this presentation i explain about the most important thing in operating system i.e Deadlock. Here i briefly explained what is deadlock, why deadlock occurs, deadlock in real life, methods of handling deadlock. Banker's algorithm and a numerical.
I hope its worth sharing!
2. What is a DEADLOCK?
A deadlock is a situation in which two computer programs sharing the same resource are
effectively preventing each other from accessing the resource, resulting in both programs
ceasing to function.
Deadlock is a situation where a set of processes are blocked because each process is
holding a resource and waiting for another resource acquired by some other process.
Learning to deal with deadlocks had a major impact on the development of operating
systems and the structure of databases. Data was structured and the order of requests was
constrained in order to avoid creating deadlocks.
5. Why DEADLOCK Occurs?
The earliest computer operating systems ran only one program at a time. All of the resources of the
system were available to this one program. Later, operating systems ran multiple programs at once,
interleaving them. Programs were required to specify in advance what resources they needed so that
they could avoid conflicts with other programs running at the same time.
Eventually some operating systems offered dynamic allocation of resources. Programs could request
further allocations of resources after they had begun running. This led to the problem of the deadlock.
Due to Multiprogramming
6. Why DEADLOCK Occurs?
Deadlock can arise if following four conditions hold simultaneously (Necessary Conditions)
1) Mutual Exclusion: One or more than one resource are non-sharable (Only one process
can use at a time).
2) Hold and Wait: A process is holding at least one resource and waiting for resources.
3) No Preemption: A resource cannot be taken from a process unless the process releases
the resource.
4) Circular Wait: A set of processes are waiting for each other in circular form.
7. Methods for handling DEADLOCKS
There are three ways to handle deadlock :-
1) Deadlock prevention or avoidance: The idea is to not let the system into deadlock
state.
2) Deadlock detection and recovery: Let deadlock occur, then do preemption to handle it
once occurred.
3) Ignore the problem all together: If deadlock is very rare, then let it happen and reboot
the system. This is the approach that both Windows and UNIX take.
8. Banker’s Algorithm
The banker’s algorithm is a
resource allocation and deadlock
avoidance algorithm that tests for
safety by simulating the
allocation for predetermined
maximum possible amounts of all
resources, then makes an “s-
state” check to test for possible
activities, before deciding
whether allocation should be
allowed to continue.
Safe sequence is the sequence in which the processes can be safely executed.
9. Example of Banker’s Algorithm
Considering a system with five processes P0 through P4 and three resources types A, B, C.
Resource type A has 10 instances, B has 5 instances and type C has 7 instances. Suppose at time
t0 following snapshot of the system has been taken:
Need [i , j] = Max [i , j] – Allocation [i , j] Need Matrix
10. Applying the Safety algorithm on the given system
The Safe Sequence is
P1, P3, P4, P0, P2 .