retagged by
21,754 views
34 votes
34 votes
Consider a system with $3$ processes that share $4$ instances of the same resource type. Each process can request a maximum of $K$ instances. Resources can be requested and releases only one at a time. The largest value of $K$ that will always avoid deadlock is ___
retagged by

5 Answers

Best answer
85 votes
85 votes
Number of processes $= 3$
Number of Resources $= 4$

Let's distribute each process one less than maximum demand $(K-1)$ resources. i.e. $3(K-1)$
Provide an additional resource to any of three processes for deadlock avoidance.

Total resources $= 3(K-1) + 1 = 3K - 2$

Now, this $3K-2$ should be less than or equal to the number of resources we have right now.
$3K-2 \leq4$
$\implies 3K \leq 6$
$\implies K \leq 2$
So, largest value of $K=2$
edited by
16 votes
16 votes
For many people being confused by the answer being either 1 or 2, here's an explanation that might help.

4 instances of R given.

3 Processes given.

Let each process take 1 resource. 1 R left. Clearly, K can be 1 since deadlock wont happen.

Now lets take 2.

In the worst case, every process will take 1 resource each with one R left out.

Assume P1 takes the remaining 1 R again and P2 requests for R. P2 will wait till P1 finishes. Therefore no deadlock. K=2.

Now lets try 3

Worst case again, each process takes 1 resource with 1 R left out. Say P1 requests for 2 more - it will lead to a deadlock since only 1 is available and 1 more is needed. Deadlock means program is literally 'dead' and 'locked' with no progress at all.

 

Therefore, K=2
1 votes
1 votes
Let demand of each process be d
Give number of process is 3 , give one less resource to all processes that is (d-1)
so maximum number of resources but still deadlock occurs is 3(d-1)
Given resources =4
4<=3(d-1)
or
4>3(d-1)
=> 4>3d-3
=>4+3>3d
=>7>3d
putting value of d as 2 we get
7>6 which is true therefore 2 is the answer
0 votes
0 votes
To avoid deadlock, it is necessary to ensure that the system will never reach a state where all processes are waiting for a resource that is held by another process. One way to avoid deadlock is to ensure that each process can always obtain the resources it needs without having to wait for another process to release them.

In a system with 3 processes and 4 instances of the same resource type, the largest value of K that will always avoid deadlock is 2. This is because if each process can request up to 2 instances of the resource at a time, then each process can always obtain the resources it needs without having to wait for another process to release them.

In general, the value of K (not necessarily the minimum) that will always avoid deadlock in a system with N processes and M instances of the same resource type is M/N. This is because each process can request up to M/N instances of the resource at a time, ensuring that each process can always obtain the resources it needs without having to wait for another process to release them. To get the minimum value of K we have to use the formula $N(K-1) + 1 \leq M$ as that’ll ensure that at least 1 process can complete without waiting for any other process which will then release the resources held by it – thus ensuring other processes too eventually finish (no deadlock).
edited by
Answer:

Related questions

27 votes
27 votes
6 answers
4
gatecse asked Feb 14, 2018
11,457 views
The set of all recursively enumerable languages is:closed under complementationclosed under intersectiona subset of the set of all recursive languagesan uncountable set