Deadlock

Question 1

A solution to the Dining Philosophers Problem which avoids deadlock is

A
ensure that all philosophers pick up the left fork before the right fork
B
ensure that all philosophers pick up the right fork before the left fork
C
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
D
None of the above
Question 1 Explanation: 
In the Dining philosopher problem, each philosopher needs exactly two chopsticks to eat food but the problem is: each philosopher is going to take one chopstick at a time, which is placed at its right-hand side or at its left-hand side, but remember all should choose in the same manner like if first one chooses in a clockwise manner then each one should choose in clockwise, this type of picking cause, a circular waiting loop because each one is depending on other. This is also called as circular waiting and it leads to deadlock.
To avoid this, atleast one philosopher should choose its first chopstick in different way so that circular loop is not formed.
Question 2

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?

A
Theory Explanation.
Question 3

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

A
3
B
5
C
4
D
6
Question 3 Explanation: 
For the system to cause deadlock give each process 1 resource less than they require. Since in this case they require 2 resource each, so just give them 1 resource each. So if at max if 3 resource will be available then there can be deadlock. So by adding one more resource deadlock will never occur. So in total minimum 4 resources are required so that deadlock will never occur.
Question 4

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?

A
6
B
5
C
4
D
3
Question 4 Explanation: 
Each process needs 2 drives. So for deadlock just give each process one drive. So total 6 process can be given 1 drive each and can cause deadlock. So to break deadlock just reduce 1 process.
So maximum no. of process for the system to be deadlock free is 5.
Question 5

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

A
Release all resources before requesting a new resource
B
Number the resources uniquely and never request a lower numbered resource than the last one requested
C
Never request a resource after releasing any resource
D
Request and all required resources be allocated before execution
Question 5 Explanation: 
Given statement is wrong. We can request a resource after releasing any resource.
Question 6

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?

A
7
B
9
C
13, 15
D
13
E
15
Question 6 Explanation: 
A requires 3, B-4, C-6;
→ 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 7

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.

A
4
B
10
C
11
D
12
E
None of the above
Question 7 Explanation: 
Algorithm: Round robin; TQ: 1

p is departure at 11.
Question 8

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:

A
2
B
3
C
4
D
1
Question 8 Explanation: 
Lets give 2 tape driver to each process, so that there will be deadlock. So 3 processes will be given two drives each so that there will be deadlock. So to avoid deadlock maximum no. of process should be 1 less than the minimum no. of process that will cause deadlock. So for n=2, the system is guaranteed to be deadlock free.
Question 9
Consider a computer system with multiple shared resource types, with one instance per resource type. Each instance can be owned by only one process at a time. Owning and freeing of resources are done by holding a global lock (L). The following scheme is used to own a resource instance:
function OWNRESOURCE(Resource R)
      Acquire lock L  //  a global lock
      if R is available then
               Acquire R
               Release lock L
        else
                if R is owned by another process P then
                      Terminate P, after releasing all resources owned by P
                      Acquire R
                      Restart P
                      Release lock L
                 end if 
         end if
  end function
Which of the following choice(s) about the above scheme is/are correct?
A
The scheme ensures that deadlocks will not occur.
B
The scheme may lead to live-lock.
C
The scheme violates the mutual exclusive property.
D
The scheme may lead to starvation.
Question 9 Explanation: 

(1) True, 

The scheme ensures deadlock free operation, as there is no hold-and-wait condition possible. 

 

(2) True, 

The scheme may lead to priority inversion problems, and hence livelock is possible. 

 

(3) False, 

Mutual exclusion is satisfied as only one process can acquire and release locks at a time.  

 

(4) True,

The scheme may lead to starvation. For example, the priority process can get scheduled repeatedly and keeps on killing the lower priority processes. Hence, a low priority process may strave.

Question 10

Two shared resources R1 and R2 are used by processes P1 and P2. Each process has a certain priority for accessing each resource. Let Tij denote the priority of Pi for accessing Rj. A process Pi can snatch a resource Rh from process Pj if Tik is greater than Tjk. Given the following:

(I) T11 > T21
(II) T12 > T22
(III) T11 < T21
(IV) T12 < T22 
Which of the following conditions ensures that P1 and P2 can never deadlock?

A
(I) and (IV)
B
(II) and (III)
C
(I) and (II)
D
None of the above
Question 10 Explanation: 
If all resources are allocated to one process then deadlock will never occur. So, if we allocate both R1 and R2 to process P1 or both R1 and R2 to process P2 then deadlock will never occur. So when one process will complete its execution then both the resources are allocated to the other process. So, either condition (I) and (II) or (III) and (IV) ensures that deadlock will never occur.
Question 11

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:

A
Both starvation and deadlock can occur
B
Starvation can occur but deadlock cannot occur
C
Starvation cannot occur but deadlock can occur
D
Neither starvation nor deadlock can occur
Question 11 Explanation: 
Starvation can occur as each time a process requests a resource it has to release all its resources.
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.
Question 12
Which of the following statements is/are TRUE with respect to deadlocks?
A
Circular wait is a necessary condition for the formation of deadlock.
B
In a system where each resource has more than one instance, a cycle in its wait-for graph indicates the presence of a deadlock.
C
If the current allocation of resources to processes leads the system to unsafe state, then deadlock will necessarily occur.
D
In the resource-allocation graph of a system, if every edge is an assignment edge, then the system is not in deadlock state.
Question 13

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 _________.

A
7
B
8
C
9
D
10
Question 13 Explanation: 
(3*2 tape units) + 1 tape unit = 7
Question 14

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?

A
1
B
2
C
3
D
6
Question 14 Explanation: 
Let's assume that each process request 2 resources each. Now there are total 6 identical resources available. Give 1 resource to every processes then there will be deadlock because now each process will wait for another resource which is not available, so there will be deadlock. Since there are total 6 resources so for deadlock to be possible there should be 6 processes available. Hence, the value of N is 6.
Question 15

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?

A
Safe, Deadlocked
B
Safe, Not Deadlocked
C
Not Safe, Deadlocked
D
Not Safe, Not Deadlocked
Question 15 Explanation: 

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 16

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 _________.

A
2
B
3
C
4
D
5
Question 16 Explanation: 
No. of process = 3
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 17

In a system, there are three types of resources: E, F and G. Four processes P0, P1, P2 and P3 execute concurrently. At the outset, the processes have declared their maximum resource requirements using a matrix named Max as given below. For example, Max[P2, F] is the maximum number of instances of F that P2 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?

A
The system is in safe state.
B
The system is not in safe state, but would be safe if one more instance of E were available.
C
The system is not in safe state, but would be safe if one more instance of F were available.
D
The system is not in safe state, but would be safe if one more instance of G were available.
Question 17 Explanation: 
〈E, F, G〉 = 〈3, 3, 0〉

Safe sequence:
〈P0, P2, P1, P3
P0: P0 can be allotted 〈3,3,0〉.
After completion Available = 〈4,3,1〉
P2: P2 can be allotted 〈0,3,0〉.
After completion: Available = 〈5,3,4〉
P1: P1 can be allotted 〈1,0,2〉.
After completion: Available = 〈6,4,6〉
P3: P3 can be allotted 〈3,4,1〉.
After completion: Available = 〈8,4,6〉
Question 18

Consider the following snapshot of a system running n concurrent processes. Process i is holding Xi 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 Yi additional instances of R while holding the Xi instances it already has. Of the n processes, there are exactly two processes p and q such that Yp = Yq = 0. Which one of the following conditions guarantees that no other process apart from p and q can complete execution?

A
Min (Xp, Xq) ≥ Min {Yk | 1 ≤ k ≤ n, k ≠ p, k ≠ q}
B
Xp + Xq < Max {Yk | 1 ≤ k ≤ n, k ≠ p, k ≠ q}
C
Min (Xp, Xq) ≤ Max {Yk | 1 ≤ k ≤ n, k ≠ p, k ≠ q}
D
Xp + Xq < Min {Yk | 1 ≤ k ≤ n, k ≠ p, k ≠ q}
Question 18 Explanation: 
{P1, P2, ..., Pn}
Pi holds Xi instances.
Pi can request additional Yi instances.
Given two process p & q such that their additional requests are zero.
Yp = Yq = 0
{Yk | 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., Yk indicates additional request of all the processes (n-2) except p & q.
For p & q to complete first, accordingly
Xp + Xq < Min {Yk}
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 Xp and Xq 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.,
Xp + Xq < Min {Yk | 1 ≤ k ≤ n, k ≠ p, k ≠ q}.
Question 19

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?

A
Any one of I and III but not II or IV
B
Any one of I, III, and IV but not II
C
Any one of II and III but not I or IV
D
Any one of I, II, III, and IV
Question 19 Explanation: 
All are deadlock prevention strategies.
Question 20

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

A
In deadlock prevention, the request for resources is always granted if the resulting state is safe
B
In deadlock avoidance, the request for resources is always granted if the result state is safe
C
Deadlock avoidance is less restrictive than deadlock prevention
D
Deadlock avoidance requires knowledge of resource requirements a priori
Question 20 Explanation: 
Deadlock prevention scheme handles deadlock by making sure that one of the four necessary conditions don't occur. So, it may be the case that a resource request might be rejected even if the resulting state is safe. Hence, option (A) is false.
Question 21

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

A
B
C
D
Question 21 Explanation: 
In the extreme situation, we have si - 1 resources and we require one more resource.
If the deadlock will never occur in the corresponding process then the following condition be true.
There are 21 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access