in Operating System edited by
29,073 views
149 votes
149 votes

A system has $n$ resources $R_0, \dots,R_{n-1}$, and $k$ processes $P_0, \dots, P_{k-1}$. The implementation of the resource request logic of each process $P_i$ is as follows:

$\text{if} (i\%2==0) \{$
$\quad\text{if} (i<n) \text{ request } R_i;$
$\quad\text{if} (i+2 < n) \text{ request } R_{i+2}; \}$
$\text{else} \{$
$\quad\text{if} (i<n) \text{ request } R_{n-i};$
$\quad\text{if} (i+2 <n) \text{ request } R_{n-i-2}; \}$

In which of the following situations is a deadlock possible?

  1. $n=40,\: k=26$
  2. $n=21,\:k=12$
  3. $n=20,\:k=10$
  4. $n=41,\:k=19$
in Operating System edited by
29.1k views

4 Comments

 @Arjun Sir @Lakshman Patel RJIT Sir Please correct the question in the PDF.  as mentioned by @JAINchiNMay 

0
0

we can solve by taking small value just like below solution 

https://gateoverflow.in/2348/gate-cse-2010-question-46?show=417063#a417063

0
0
In the gate previous PYQ's pdf, the condition for odd processes is missing. Please update that in the pdf.
0
0

6 Answers

332 votes
332 votes
Best answer
From the resource allocation logic, it's clear that even numbered processes are taking even numbered resources and all even numbered processes share no more than $1$ resource. Now, if we make sure that all odd numbered processes take odd numbered resources without a cycle, then deadlock cannot occur. The "else" case of the resource allocation logic, is trying to do that. But, if $n$ is odd, $R_{n-i}$ and $R_{n-i-2}$ will be even and there is possibility of deadlock, when two processes requests the same $R_i$ and $R_j$. So, only $B$ and $D$ are the possible answers.

Now, in $D$, we can see that $P_0$ requests $R_0$ and $R_2$, $P_2$ requests $R_2$ and $R_4$, so on until, $P_{18}$ requests $R_{18}$ and $R_{20}$. At the same time $P_1$ requests $R_{40}$ and $R_{38}$,  $P_3$ requests $R_{38}$ and $R_{36}$, so on until, $P_{17}$ requests $R_{24}$ and $R_{22}$. i.e.; there are no two processes requesting the same two resources and hence there can't be a cycle of dependencies which means, no deadlock is possible.

But for $B$, $P_8$  requests $R_8$ and $R_{10}$ and $P_{11}$ also requests $R_{10}$ and $R_8$. Hence, a deadlock is possible. (Suppose $P_8$ comes first and occupies $R_8$. Then $P_{11}$ comes and occupies $R_{10}$. Now, if $P_8$ requests $R_{10}$ and $P_{11}$ requests $R_8$, there will be deadlock)

Correct Answer: $B$
edited by
by

15 Comments

just a small correction Sir there will be no P19 in case (D) as k=19 so P will be from 0 to 18

10
10
Thanks for the correction :)
4
4
Thanks..fantastic answer
3
3
very clear explanation arjun sir
1
1
at option, B...how to reach to P8 and P11...just trial and error of any other method?
0
0
check answer given by ishaan sood
2
2
Thqqq soo much ..crystal clear explanation...
1
1
great explanation
0
0
Can you plz explain dat more elaborately???
0
0
Thanks sir ji
0
0
How can we tackle such questions in exam.. Seriously!! :(
0
0
Question is like odd man out,right?

Otherwise P0 requesting for P2 and P2 also requesting for P2, there also possibility of deadlock , right?
0
0
Is there any method with out brute force method to solve these type of problems ?
1
1
Such a nice explanation.
0
0
Mind blowing explanation !!
0
0
18 votes
18 votes
Option B is answer

No. of resources, n = 21
No. of processes, k = 12

Processes {P0, P1....P11}  make the following Resource requests:
{R0, R20, R2, R18, R4, R16, R6, R14, R8, R12, R10, R10}

For example P0 will request R0 (0%2 is = 0 and 0< n=21). 

Similarly, P10 will request R10.

P11 will request R10 as n - i = 21 - 11 = 10.

As different processes are requesting the same resource, deadlock
may occur. 

2 Comments

how every process is requesting only 1 resource?

according to the code it is requesting 2 resources...
1
1
@Abhineet Singh

its like Give one resource and then prempt and go to the other process and give it another resource
1
1
14 votes
14 votes

The answer

2 Comments

@

But (d) is also satisfying 1 and 2.

 

0
0
option D is not satisfying, for D k=19 and n=41, so (41-2)/2=19.5, so it is not satisfying the k>=(n-2)/2 condition
0
0
4 votes
4 votes
Even numbered process Pi request even numbered resources Ri and Ri+2. Thus they share no more than 1 resource.
Odd numbered process Pi request
Odd numbered resources Rn−i and Rn−i−2 if nn is even
Even numbered resources Rn−i and Rn−i−2 if n is odd.
In this example, for deadlock to occur, two processes must request same set of processes. For this, we need n to be odd so that some odd numbered process will request same set of even numbered resources as some even numbered process.
Thus option A and C are not possible as they have even n.
Now easy way to solve this is by finding the resources of even and odd numbered processes by using the given answer.
Taking option B:
Even numbered processes resource allocation-           
P0      R0 , R2
P2      R2, R4
P4      R4, R6
P6      R6, R8
P8      R8, R10
P10    R10 , R12
Odd numbered processes resource allocation-
P1      R20, R18
P3      R18, R16
P5      R16, R14
P7     R14, R12
P9     R12, R10
P11   R10, R8

IF YOU SEE BOTH YOU WILL FIND P10 AND P9 REQUESTING SAME RESOURCES WHICH MAY LEAD TO DEADLOCK.​​​​​​​

edited by

1 comment

Even process p0 and p1 are requesting for resource R2 in every case isn't that a deadlock?
0
0
Answer:

Related questions