Professional Documents
Culture Documents
RESOURCES:
Hardware
Database
Files
I/O
Etc
Deadlock occurs when a set of processes are blocked because each process is holding a resource
and waiting for a resource which is in the possession of another process.
Fig 2
For deadlock to happen or take place, there are four necessary conditions that needs to be
satisfied. The following are the four necessary conditions for deadlock to occur:
1. Mutual Exclusion
3. No preemption
4. Circular Wait
MUTUAL EXCLUSION
Fig 3
X – R has been assigned to A1 by OS
In mutual exclusion one or more resources available cannot be shared ex. Printer; i.e. to say only
one process can use it at a time. Considering the fig 3, A1 and A2 are two different processes and
R being a resource both A1 and A2 need. In our scenario R has been assigned to A1 OR
implying A2 cannot access it since R is not shareable (mutual exclusion). Not until A1 releases
R, A2 can never have access to R leading to what is known as deadlock situation.
Fig 4
Considering Fig 4
In this scenario, a process is holding at least one resource and waiting for other resources
X – A1 is holding R2 and R3; A1 has requested for another resource R1 and is waiting for R1 to
be released by A2.
It will not release R2 and R3 to any other process not until after getting R1. That is to say, if
it has even finished using R2 and R3, it will not release them not until it gets R3. A1 will not
get access to R1 as A2 is holding it due to mutual exclusion.
A1 is waiting for R1 whiles holding unto R2 and R3. A1 will release R2 and R3 only after
getting R1 even if it has finished using R2 and R3
Fig 5
In this case, a resource assigned to a process by the OS cannot be taken away from it unless the
process releases it.
Z – R has been assigned to A1 i.e. A1 is holding R and will only release it after using (execution)
it. The OS cannot interrupt it because the condition is pre-emptive
CIRCULAR WAIT
Under this condition, a set of processes are waiting for each other in a circular form.
Considering a simple circular wait scenario, let A1 and A2 be processes and R1 and R2
resources from Fig
Fig 6
X – A1 requests R1 (it needs it) but R1 has been assigned to A2 so A1 cannot have access to it.
Y – A2 holds R1
W – A1 holds R2
Under this condition A1 requests for R1 but cannot have access to it R1 has been assigned to A2.
Similarly A2 requests for resource R2 but cannot have access to it because it has been assigned
by the operating system to the process A1. You can see it is in a circular form.
NB: For deadlock to occur, all the four conditions should occur simultaneously.
Generally there are three main methods/ways or strategies to handle deadlock, namely:
The idea in this case is to make sure the system does not get to the deadlock state/stage.
Is to make deadlock to occur then preempt the system to handle the situation
When deadlock is seen or observed to be rare and also not critical, you allow it to occur (you
may pretend that deadlock can never occur) after which system is rebooted.
1. Pre – emption --- In this case resource from one process can be taken and given to another for
it to complete. This sometimes causes problems.
2. Roll Back --- in this case, records of each process is kept from time to time and in
situation where deadlock is possible, the system is rolled back to the last recorded state
(or check point) to restart from there by the allocation of different resource. Even
though there will be loss of progress (time), as a result of the restarting, the allocation of
the different resource(s) is required to avoid the re- occurrence of deadlock.
3. Killing of one or more Processes --- In this case, one or more processes are killed, but
remember, after killing a process, you have to restart it and cannot guarantee if deadlock
will not re-occur after the restart. It’s the simplest or easiest.