• retagged by
42,413 views
59 59 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 ___

7 Answers

Best answer
140 140 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
27 27 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
3 3 votes
We can use Pigeon Hole principle in this problem.

Give P1 , P2 AMD P3  each an equal resources 1, 1, 1

as per PGP we know that there is atleast 2 pigeon in a same hole so here one resources i sleft add it to any process and the max value of K= 1+1 =2
2 2 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 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
0 0 votes

Number of processes, N = 3

Number of resources available = 4

Minimum resources required to avoid deadlock with N processes when each process can request at most K instances=

N(K-1)+1

If the minimum number of resources required to avoid deadlock is more than number of resources available, we CANNOT fulfil any request.

So, 

N(K-1)+1 <= Available

3(K-1)+1 <= 4

3K-2 <= 4

3K <= 6

K <= 2

Maximum value of K to avoid deadlock = 2

Answer:
Position:
Show:

Related questions

43 43 votes
4 answers 4 answers
24.4k
24.4k views
gatecse asked Feb 14, 2018
24,385 views
In a system, there are three types of resources: $E, F$ and $G$. Four processes $P_0$, $P_1$, $P_2$ and $P_3$ execute concurrently. At the outset, the processes have decl...
57 57 votes
6 answers 6 answers
27.7k
27.7k views
gatecse asked Feb 14, 2018
27,743 views
Consider the following problems. $L(G)$ denotes the language generated by a grammar $G$. L(M) denotes the language accepted by a machine $M$.For an unrestricted grammar $...
37 37 votes
6 answers 6 answers
18.1k
18.1k views
gatecse asked Feb 14, 2018
18,137 views
Match the following:$$\begin{array}{|l|l|}\hline \textbf{Field} & \textbf{Length in bits} \\\hline \text{P. UDP Header's Port Number} & \text{I. 48} \\ \text{Q. Ethern...
44 44 votes
7 answers 7 answers
17.0k
17.0k views
gatecse asked Feb 14, 2018
17,034 views
Consider the following two tables and four queries in SQL.Book (isbn, bname), Stock(isbn, copies)Query 1: SELECT B.isbn, S.copies FROM Book B INNER JOIN Stock S ON B.isbn...