Q1. Solve the following problem of Deadlock avoidance. Allocate the resources such that all the process are executed safe and no deadlock is occur.
Total instances of a resource=10
Process |
Has |
Maximum |
P1 |
2 |
4 |
P2 |
2 |
7 |
P3 |
3 |
9 |
Free |
Solution:
Given data
Process | Has | Maximum Needed | Remaining Needs After Allocation |
P1 | 2 | 4 | 4-2=2 |
P2 | 2 | 7 | 7-2=5 |
P3 | 3 | 9 | 9-3=6 |
Here we know that total number of resources available are 10
So Total number of resources which are free = total resources - sum(allocated resources)
i.e Available resources = 10 - (2+2+3) = 3
Available Resources |
3 |
Here available resources are 3.
For avoiding deadlock we need to allocate the resources whose needs are meeting with the available resources.
So from the given processes P1 requires 2 resources,P2 requires 5 resources where as P3 requires 6 resources.
Here available resources are 3 so we can allot the 2 resources needed for process P1.
i.e
Available Resources after alloting to process P1 |
3-2=1 |
Now assume process p1 has completed that means it will relase all its resouces i.e 4 will be added to available resources.
Available Resources after completion of P1 |
Prev Available + P1 releases resources = 1 + 4 = 5 |
Now we have available resources as 5. Since P1 is completed the remaining processes are P2,P3 which requires 5 and 6 resources to complete the execution.
Here process P2 requires 5 resources and the available resources also 5 so we can allot those resources to process P2.
i.e
Available Resources after alloting to process P2 |
5 - 5 = 0 |
Now P2 has all needed resources so it will complete its execution and will release the resources it has i.e 7.
Available Resources after completion of P2 |
Prev Available + P2 releases resources = 0 + 7 = 7 |
Till now P1,P2 are executed safely without any deadlock.
Now the final remaining process is P3 which requires 6 more resources to execute . Here available resources are 7 so assign 6 resources to process P3.
Available Resources after alloting to process P3 |
7 - 6 =1 |
Since all needed resources allocated P3 will completer its execution and releases the resources.
Available Resources after completion of P3 |
Prev Available + P3 releases resources = 1 + 9 = 10 |
Final Available resources after completion of all processes should equal to total instance of resources i.e 10
Available Resources after completion of All processes |
10 |
Here P1,P2,P3 executed without any deadlock. So the system is in safe state and the safe sequence is P1,P2,P3.
Note: if you have any queries please post a comment thanks a lot... always available to help you....
Get Answers For Free
Most questions answered within 1 hours.