in Operating System edited by
5,367 views
24 votes
24 votes

A computer system has $6$ tape devices, with n processes competing for them. Each process may need $3$ tape drives. The maximum value of n for which the system is guaranteed to be deadlock-free is:

  1. $2$
  2. $3$
  3. $4$
  4. $1$
in Operating System edited by
5.4k views

4 Answers

12 votes
12 votes
Best answer
Allocate max-$1$ resources to all processes and add one more resource to any process (Pigeon hole principle) so that this particular process can be completed (resources can be freed) and there is no deadlock.

Max resources required is $3$.

$\therefore (3-1)*n+1=6$

$n=\left \lfloor \frac{5}{2} \right \rfloor=2$

Correct Answer: $A$
edited by

3 Comments

Please explain me this-

if I take 4 processes as- P1, P2, P3, P4 and allocate resources as 1, 1, 1, 3 respectively, then P4 will complete its task and release the resources held by it and hence others can complete their task. And hence the system is deadlock free by taking 4 processes.

Please help where am I missing the concept.
0
0
edited by

@PriyankaS

P1 P2 P3 P4
1 1 1 1
1 1    

The case which you have taken will not lead to deadlock but if I consider this case for your example then there will be a deadlock.

So we need such a number of process in which if we try for any possibility deadlock should  not occur!

1
1

@PriyankaS I might be late But here we talk of the worst case. In the worst case if we have more than 2 processes here then it will lead to a deadlock. 

 You can even understand it using PHP(pigeonhole principle) we have 6 Resources(as pigeons) we have to distribute into the max processes(as holes) such that at least one of them will have 3 resources.

 then ceil(6/P) = 3 now if p =2 then only it will be 3 cause we need max process.

0
0
18 votes
18 votes

Answer: (A).

For $n=3$, $2-2-2$ combination of resources leads to deadlock.

For $n=2$, $3 - 3$ is the maximum need and that can always be satisfied.

edited by

4 Comments

I may be a bit late to ask this question. But nonetheless...

Consider there are 4 processes and each process has 1 resource. There will be two resources remaining. One of the four process may ask for 2 resources and the resulting state will be a safe state. (Infact, one of the resource can request only one tape device and even after that it will be in safe state.) So the max process will be 4(option C) right?
0
0

your assumption is good. But you should take care of question statement in the question statement it has been said that 

"The maximum value of n for which the system is guaranteed to be deadlock free is"

here guaranteed word is used and due to this word your answer is not correct so if guaranteed is not used in question statement in that case you may be correct.

8
8

@GaneshA We can come up with many such allocation which will not cause deadlock. Question is asking "guaranteed to be deadlock free". Even if there is is a single case causing deadlock, it will not be considered.

Worst case allocation is all process gets one less than their maximum demand and all are blocked as after such assignment no one goes to completion.

0
0

Please explain, I am not able to understand.

If I take 4 processes as- P1, P2, P3, P4 and allocate resources as 1, 1, 1, 3 respectively, then P4 will complete its task and release the resources held by it and hence others can complete their task. And hence the system is deadlock free by taking 4 processes.

How come using 4 processes deadlock free is not guaranteed?

Please help where am I missing the concept.

0
0
2 votes
2 votes
Don’t use formulas until and unless it’s necessary!

This can easily be solved with the help of intuition. Ultimately, we want that at least one process should get executed completely, so 1st process consumes 3 resources. We are left with 3 more, now if we take 2 more processes then what might happen is each of 3 processes consume 2-2 resources each because of which deadlock occurs. So, at max only 1 more process we can select and it will be consuming the remaining 3 resources. So, total of 2 processes which give n =2, option A. I hope it helped. :)
1 vote
1 vote

We need to only that option in which system will always be deadlock free..

Case 1 if we have 4 processes.  indeed we do have possibility of deadlock with 4 processes.

p1 p2 p3 p4
1 1 1 1
1 1    


Case 2 if we have 3 processes. Again with 3 processes we can have deadlock

p1 p2 p3
1 1 1
1 1 1


Case 3 if we have 2 processes. With 2 processes we can never have deadlock in any configuration..

p1 p2
1 1
1 1
1 1


We have to discard all the cases where we can have deadlock..2 is the only option in which system will be deadlock free.

Answer:

Related questions