## Deadlock

Question 1 |

Consider the following snapshot of a system running n concurrent processes. Process i is holding X_{i} instances of a resource R, 1 ≤ i ≤ n. Assume that all instances of R are currently in use. Further, for all i, process i can place a request for at most Y_{i} additional instances of R while holding the X_{i} instances it already has. Of the n processes, there are exactly two processes p and q such that Y_{p} = Y_{q} = 0. Which one of the following conditions guarantees that no other process apart from p and q can complete execution?

Min (X _{p}, X_{q}) ≥ Min {Y_{k} | 1 ≤ k ≤ n, k ≠ p, k ≠ q} | |

X _{p} + X_{q} < Max {Y_{k} | 1 ≤ k ≤ n, k ≠ p, k ≠ q} | |

Min (X _{p}, X_{q}) ≤ Max {Y_{k} | 1 ≤ k ≤ n, k ≠ p, k ≠ q} | |

X _{p} + X_{q} < Min {Y_{k} | 1 ≤ k ≤ n, k ≠ p, k ≠ q} |

_{1}, P

_{2}, ..., P

_{n}}

P

_{i}holds X

_{i}instances.

P

_{i}can request additional Y

_{i}instances.

Given two process p & q such that their additional requests are zero.

Y

_{p}= Y

_{q}= 0

{Y

_{k}| 1 ≤ k ≤ n, k ≠ p, k ≠ q} means that out of 'n' processes, we are left with (n-2) process (except p&q), i.e., Y

_{k}indicates additional request of all the processes (n-2) except p & q.

For p & q to complete first, accordingly

X

_{p}+ X

_{q}< Min {Y

_{k}}

Option D is correct.

There are exactly two process p and q which do not need any additional instances of resources.

So, p and q will complete their execution and will release X

_{p}and X

_{q}instances of resources.

Now to guarantee that no other process apart from p and q can complete execution, the no. of instances of resources available must be less than the minimum no. of instances of resources required by any other process, i.e.,

X

_{p}+ X

_{q}< Min {Y

_{k}| 1 ≤ k ≤ n, k ≠ p, k ≠ q}.

Question 2 |

Consider a system with 3 processes that share 4 instances of the same resource type. Each process can request a maximum of K instances. Resource instances can be requested and released only one at a time. The largest value of K that will always avoid deadlock is _________.

2 | |

3 | |

4 | |

5 |

No. of resources = 4

Let’s distribute each process one less than maximum demands i.e., (k-1) resources.

So, for three processes, 3(k – 1) resources.

For deadlock avoidance provide an additional resource to any one of the process.

∴ Total resources required to avoid deadlock in any case is 3(k – 1) + 1 = 3k – 2

Now this 3k – 2 should be less than equal to available no. of resources, i.e.,

3k – 2 ≤ 4

k ≤ 2

So maximum value of k = 2

Question 3 |

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 declared their maximum resource requirements using a matrix named Max as given below. For example, Max[P_{2}, F] is the maximum number of instances of F that P_{2} would require. The number of instances of the resources allocated to the various processes at any given state is given by a matrix named Allocation.

Consider a state of the system with the Allocation matrix as shown below, and in which 3 instances of E and 3 instances of F are the only resources available.

From the perspective of deadlock avoidance, which one of the following is true?

The system is in safe state. | |

The system is not in safe state, but would be safe if one more instance of E were available. | |

The system is not in safe state, but would be safe if one more instance of F were available.
| |

The system is not in safe state, but would be safe if one more instance of G were available. |

Safe sequence:

〈P

_{0}, P

_{2}, P

_{1}, P

_{3}〉

P

_{0}: P

_{0}can be allotted 〈3,3,0〉.

After completion Available = 〈4,3,1〉

P

_{2}: P

_{2}can be allotted 〈0,3,0〉.

After completion: Available = 〈5,3,4〉

P

_{1}: P

_{1}can be allotted 〈1,0,2〉.

After completion: Available = 〈6,4,6〉

P

_{3}: P

_{3}can be allotted 〈3,4,1〉.

After completion: Available = 〈8,4,6〉

Question 4 |

A system shares 9 tape drives. The current allocation and maximum requirement of tape drives for three processes are shown below:

Which of the following best describe current state of the system?

Safe, Deadlocked | |

Safe, Not Deadlocked | |

Not Safe, Deadlocked | |

Not Safe, Not Deadlocked |

Available: (9 - (3 + 1 + 3)) = 2, P3 can be satisfied.

New available = 3 + 2 = 5

Now, P2 can be satisfied.

New available: 5 + 1 = 6

Now, P1 can be satisfied. Thus safe sequence: P3 → P2 → P1

That is not deadlocked.

Question 5 |

A system has 6 identical resources and N processes competing for them. Each process can request atmost 2 resources. Which one of the following values of N could lead to a deadlock?

1 | |

2 | |

3 | |

6 |

Question 6 |

Consider the following policies for preventing deadlock in a system with mutually exclusive resources.

- I. Processes should acquire all their resources at the beginning of execution. If any resource is not available, all resources acquired so far are released.

II. The resources are numbered uniquely, and processes are allowed to request for resources only in increasing resource numbers.

III. The resources are numbered uniquely, and processes are allowed to request for resources only in decreasing resource numbers.

IV. The resources are numbered uniquely. A process is allowed to request only for a resource with resource number larger than its currently held resources.

Which of the above policies can be used for preventing deadlock?

Any one of I and III but not II or IV | |

Any one of I, III, and IV but not II | |

Any one of II and III but not I or IV | |

Any one of I, II, III, and IV |

Question 7 |

A system contains three programs and each requires three tape units for its operation. The minimum number of tape units which the system must have such that deadlocks never arise is _________.

7 | |

8 | |

9 | |

10 |

Question 8 |

A system has n resources R_{0},...,R_{n-1},and k processes P_{0},....P_{k-1}.The implementation of the resource request logic of each process P_{i} is as follows:

if (i % 2 == 0) { if (i < n) request R_{i}if (i+2 < n) request R_{i+2}} else { if (i < n) request R_{n-i}if (i+2 < n) request R_{n-i-2}}

In which one of the following situations is a deadlock possible?

n = 40, k = 26 | |

n = 21, k = 12 | |

n = 20, k = 10 | |

n = 41, k = 19 |

P

_{10}requests R

_{10}& R

_{11}

P

_{11}requests R

_{10}& R

_{8}

Hence P

_{10}& P

_{11}inorder in deadlock.

Question 9 |

Consider a system with 4 types of resources R1 (3 units), R2 (2 units), R3 (3 units), R4 (2 units). A non-preemptive resource allocation policy is used. At any given instance, a request is not entertained if it cannot be completely satisfied. Three processes P1, P2, P3 request the sources as follows if executed independently.

Which one of the following statements is TRUE if all three processes run concurrently starting at time t=0?

All processes will finish without any deadlock. | |

Only P1 and P2 will be in deadlock. | |

Only P1 and P3 will be in a deadlock. | |

All three processes will be in deadlock. |

→ P1 requests 2 units of R2 which is granted.

→ P2 requests 2 units of R3 which is granted.

→ P3 requests 1 units of R4 which is granted.

Now Available resources are,

At t=1,

→ P1 requests 1 unit of R3 which is granted because it is available.

Now Available resources are,

At t=2,

→ P2 requests 1 unit of R4 which is granted.

→ P3 requests 2 units of R1.

Now Available resources are,

At t=3,

→ P1 requests 2 units of R1 which cannot be granted, and will wait for other processes to release.

Available resources are,

At t=4,

→ P2 requests 1 unit of R1, which is granted.

Available resources are

At t=5,

→ P3 releases 2 units of R1.

Now Available resources are,

→ Now P1 is waiting for R1, so now P1 will be granted 2 units of R1.

Now Available resources are,

→ Now P1 releases 1 unit of R2 and 1 unit of R1.

Now Available resources are

At t=6,

→ Now P2 releases 1 unit of R3.

Now available resources are,

At t=7,

→ P3 requests 1 unit of R2, which is granted.

→ P1 releases 1 unit of R3.

Now Available resources are,

At t=8,

→ P2 fnishes and releases remaining resources. So now Available resources,

→ P3 requests 1 unit of R3 which is granted.

Now Available resources are,

→ P1 requests 2 units of R4 which cannot be granted, so it will wait for other process to release them.

At t=9,

→ P3 finishes, and releases rest of the resources.

Now Available resources are

→ Now, P1 can be granted with resources 2 units of R4 for which it was waiting for.

Now Available resources are,

At t=10,

→ P1 finishes its execution.

So, finally we can conclude that all processes will finish without any deadlock.

Question 10 |

Which of the following is NOT true of deadlock prevention and deadlock avoidance schemes?

In deadlock prevention, the request for resources is always granted if the resulting state is safe | |

In deadlock avoidance, the request for resources is always granted if the result state is safe | |

Deadlock avoidance is less restrictive than deadlock prevention | |

Deadlock avoidance requires knowledge of resource requirements a priori |

Question 11 |

Consider the following snapshot of a system running n processes. Process i is holding x_{i} instances of a resource R, 1≤i≤n. Currently, all instances of R are occupied. Further, for all i, process i has placed a request for an additional y_{i} instances while holding the x_{i} instances it already has. There are exactly two processes p and q such that y_{p} = y_{q} = 0. Which one of the following can serve as a necessary condition to guarantee that the system is not approaching a deadlock?

min (x _{p}, x_{q}) < max_{k≠p,q}y_{k} | |

x _{p} + x_{q} ≥ min_{k≠p,q}y_{k} | |

max (x _{p}, x_{q}) > 1 | |

min (x _{p}, x_{q}) > 1 |

→ When two (or) more processes waiting for another process to release the resources.

→ P and Q can execute if they have sufficient resources, they don’t wait for extra resources (i.e., X

_{p}+ X

_{q}) required.

→ Option B can satisfies the corresponding equation i.e., X

_{p}+ X

_{q}>= min(Y

_{k}) where k != p and k != q.

Here we have sufficient resources.

Question 12 |

Suppose n processes, P_{1}, …., P_{n} share m identical resource units, which can be reserved and released one at a time. The maximum resource requirement of process P_{i} is s_{i}, where s_{i}>0. Which one of the following is a sufficient condition for ensuring that deadlock does not occur?

_{i}- 1 resources and we require one more resource.

If the deadlock will never occur in the corresponding process then the following condition be true.

Question 13 |

Which of the following is NOT a valid deadlock prevention scheme?

Release all resources before requesting a new resource | |

Number the resources uniquely and never request a lower numbered resource than the last one requested | |

Never request a resource after releasing any resource | |

Request and all required resources be allocated before execution |

Question 14 |

A computer has six tape drives, with n processes competing for them. Each process may need two drives. What is the maximum value of n for the system to be deadlock free?

6 | |

5 | |

4 | |

3 |

So maximum no. of process for the system to be deadlock free is 5.

Question 15 |

An operating system contains 3 user processes each requiring 2 units of resource R. The minimum number of units of r such that no deadlocks will ever arise is

3 | |

5 | |

4 | |

6 |

Question 16 |

A solution to the Dining Philosophers Problem which avoids deadlock is

ensure that all philosophers pick up the left fork before the right fork | |

ensure that all philosophers pick up the right fork before the left fork | |

ensure that one particular philosopher picks up the left fork before the right fork, and that all other philosophers pick up the right fork before the left fork | |

None of the above |

To avoid this, atleast one philosopher should choose its first chopstick in different way so that circular loop is not formed.

Question 17 |

A computer system uses the Banker’s Algorithm to deal with deadlocks. Its current state is shown in the table below, where P0, P1, P2 are processes, and R0, R1, R2 are resources types.

(a) Show that the system can be in this state.

(b) What will the system do on a request by process P0 for one unit of resource type R1?

Theory Explanation. |

Question 18 |

Consider a system having m resources of the same type. These resources are shared by 3 processes A, B and C, which have peak demands of 3, 4 and 6 respectively. For what value of m deadlock will not occur?

7 | |

9 | |

13, 15 | |

13 | |

15 |

→ If A have 2, B have 3, C have 5 then deadlock will occur i.e., 2+3+5=10.

→ If we have one extra resource then deadlock will not occur i.e., 10+1=11.

→ If we have equal (or) more than 11 resources then deadlock will never occur.

Question 19 |

Assume that the following jobs are to be executed on a single processor system

The jobs are assumed to have arrived at time 0^{+} and in the order p, q, r, s, t. Calculate the departure time (completion time) for job p if scheduling is round robin with time slice 1.

4 | |

10 | |

11 | |

12 | |

None of the above |

p is departure at 11.

Question 20 |

A computer system has 6 tape drives, with n process completing 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:

2 | |

3 | |

4 | |

1 |

Question 21 |

An operating system implements a policy that requires a process to release all resources before making a request for another resource. Select the TRUE statement from the following:

Both starvation and deadlock can occur | |

Starvation can occur but deadlock cannot occur | |

Starvation cannot occur but deadlock can occur | |

Neither starvation nor deadlock can occur |

Now, maybe the process has not used the resources it released yet. This may happen again when the process requests another resource.

So, the process starved for proper utilization of resources.

Deadlock will not occur as it is one of the deadlock prevention scheme.