Program for Deadlock free condition in Operating System
Given: A system has R identical resources, P processes competing for them and N is the maximum need of each process. The task is to find the minimum number of Resources required So that deadlock will never occur.
R >= P * (N - 1) + 1
Input : P = 3, N = 4 Output : R >= 10 Input : P = 7, N = 2 Output : R >= 8
Consider, 3 process A, B and C.
Let, Need of each process is 4
Therefore, The maximum resources require will be 3 * 4 = 12 i.e, Give 4 resources to each Process.
And, The minimum resources required will be 3 * (4 – 1) + 1 = 10.
i.e, Give 3 Resources to each of the Process, and we are left out with 1 Resource.
That 1 resource will be given to any of the Process A, B or C.
So that after using that resource by any one of the Process, It left the resources and that resources will be used by any other Process and thus Deadlock will Never Occur.
R >= 10
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.