Operating System MCQ

CPU Scheduling

Q.1 There are five jobs, A, B, C, D, and E, waiting in the ready queue. Their expected runtimes are 80, 60, 10, x, and 40. Suppose all the jobs are entered in the ready queue at the same time. Find the order of the jobs scheduled by the scheduler such that the average response time is minimized if 40 > x > 10.

  1. C, E, D, B, A
  2. B, A, E, C, D
  3. C, D, E, B, A
  4. C, B, A, D, E
   

Ans. (c)

Explanation – The average response time is the average of the difference between the arrival time and the time when the job gets the CPU for the first time.

Average response time = ∑ (Arrival time of each job – The time when they get the CPU for the first time) / Number of jobs

The shortest job first algorithm is the way to minimize the average response time:

Suppose all the possible values of x

If 0 < x <= 10, then the order of the jobs will be D, C, E, B, A

If 10 < x <= 40, then the order of the jobs will be C, D, E, B, A

If 40 < x <= 60, then the order will be C, E, D, B, A

If 60 < x <= 80, then the order will be C, E, B, D, A

If x > 80, then the order will be C, E, B, A, D

Hence, the answer is C, D, E, B, A

Q.2 Consider the following data:

Process Arrival Time Burst Time
P1 1 3
P2 2 1
P3 3 2
P4 4 6
P5 5 4

The round-robin scheduling algorithm is applied on the given with time quantum = 2 units. The time taken in context switching is 1 unit. What are the completion time and turnaround time of process P5?

  1. 24 units and 18 units
  2. 22 units and 17 units
  3. 23 units and 17 units
  4. 23 units and 18 units
   

Ans. (d)

Explanation: Given, Time quantum (TQ) = 2 units,

Time in context switching = 1 unit

The Gant chart will be like this:

  P1 P2 P3 P4 P1 P5 P4 P5 P4
0-1 1-2 2-4 4-5 5-6 6-7 7-9 9-10 10-12 12-13 13-14 14-15 15-17 17-18 18-20 20-21 21-23 23-24 24-26

Here, ࢚ represents the context switch.

Completion Time of P5 = 23 units

Turnaround time of P5 = CT – AT = 23 – 5 = 18 units

Hence, the correct answer is 23 units and 18 units.

Q.3 Match the following options

Group 1 Group 2
1. First come first serve A. Minimizes the average waiting time
2. Round Robin B. Every Process gets a chance to execute
3. Priority Scheduler C. Processes are run in the order they arrive
4. Shortest Remaining time first D. Important process gets executed first
  1. 1-C, 2-B, 3-D, 4-A
  2. 1-C, 2-D, 3-B, 4-A
  3. 1-C, 2-B, 3-A, 4-D
  4. 1-B, 2-C, 3-D, 4-A
   

Ans. (a)

Types of CPU Scheduling algorithms

SRTF (Shortest remaining time first) – It minimizes the average waiting time and average turnaround time.

Round Robin – Each process is executed after another for a fixed interval of time called time quantum.

Priority Scheduler – The process of higher priority gets executed first.

First come first serve – As the name suggests, the process that arrives first gets executed first.

Hence, the correct answer is 1-C, 2-B, 3-D, 4-A.

Q.4 Consider the following data,

Process Arrival Time (AT) Burst Time (BT)
P1 0 7
P2 1 4
P3 2 10
P4 3 5

Assume that the shortest remaining time first (SRTF) is used. Calculate the average waiting time.

  1. 6.50 units
  2. 7.00 units
  3. 6.25 units
  4. 7.50 units
   

Ans. (c)

Explanation: The shortest remaining time first algorithm is used, the Gant chart will look like this

P1 P2 P4 P1 P3
0-1 1-5 5-10 10-16 16-26

From the above Gant chart, we can find the completion time (CT), turnaround time (TAT), and waiting time (WT).

Process AT BT CT TAT WT
P1 0 7 16 16 9
P2 1 4 5 4 0
P3 2 10 26 24 14
P4 3 5 10 7 2

Average waiting time = (9+0+14+2)/4 = 6.25 units

Q.5 A system has 20 processes, assume that they all spend 80%time waiting in the system. Find the CPU utilization (in percentage).

  1. 99
  2. 97
  3. 96
  4. 98
   

Ans. (a)

Explanation: The CPU utilization is equal to 1-p^N, where N is the number of processes and p is the waiting fraction.

Here, N = 10 and p = 0.80

CPU utilization = 1 – (0.80)^ 20 = 1 – 0.01 = 0.99

Hence, the correct answer is 99 percent.

Q.6 Which of the CPU scheduling algorithms ensures the least average waiting time.

  1. Longest remaining time first (LRTF)
  2. Round Robin
  3. Shortest Job First (SJF)
  4. Priority Scheduling
   

And. (c)

Explanation: Shortest job first has the least average waiting time as it is the optimal scheduling algorithm.

Q.7 Which of the statement is False:

  1. SRTF may cause starvation
  2. Preemptive scheduling algorithm may cause starvation
  3. Longest remaining time first does not cause starvation
  4. Response time is better in the First come first serve algorithm than in the Round Robin
   

Ans. (d)

Explanation:a) SRTF may cause starvation for the processes with high burst time

b) Preemptive may also cause starvation for the processes with low priority

c) Longest remaining time first does not cause starvation

d) Round-robin is better than the FCFS in terms of response time.

Q.8 Assume three processes start at the same time. The first 30% of the time was spent on the input-output process, and the rest 80% of the time was spent on computing. Each process takes 40, 60, and 80 units from start to end. The first come first serve algorithm is used. How long does the CPU remain idle if all the input-output processes are overlapped?

  1. 10
  2. 8
  3. 12
  4. 6
   

Ans. (b)

Explanation: Consider the three processes, P1, P2, and P3, and their BT is 32, 48, and 64 units, respectively.

Time spent by P1, P2, and P3 on input-output is 8, 12, and 16 units, respectively.

Hence, the correct answer is 8 units.

Q. 9Which of the combination of scheduling algorithms may cause starvation:

  1. Round Robin and First Come First Serve
  2. FCFS and Multilevel feedback queue
  3. LRTF and RR
  4. Priority and SJF
   

Ans. (d)

Explanation:Starvation is caused by SJF, SRTF, LJF, Priority, and Multilevel feedback queue.

Hence, the correct answer is Priority and Shortest Job First (SJF).

Q. 10 Consider the following data:

Process Arrival Time Burst Time
P1 0 7
P2 1 5
P3 2 3
P4 3 1
P5 4 2
P6 5 1

If the shortest remaining time first is used, calculate the average waiting time and average turnaround time.

  1. 4 units and 7 units
  2. 3 units and 8.1 units
  3. 4 units and 6 units
  4. 4 units and 7.1 units
   

Ans. (d)

Explanation: Shortest remaining time first is used, the Gant chart will look like this:

P1 P2 P3 P4 P3 P6 P5 P2 P1
0-1 1-2 2-3 3-4 4-6 6-7 7-9 9-13 13-19

Form the above Gant chart, we can find the CT, TAT, and WT.

Process AT BT CT TAT WT
P1 0 7 19 19 12
P2 1 5 13 12 7
P3 2 3 6 4 1
P4 3 1 4 1 0
P5 4 2 9 5 3
P6 5 1 7 2 1

Average Turnaround time = (19 + 12 + 4 + 1 + 5 + 2)/6 = 7.1

Average Waiting Time = (12 + 7 + 1 + 0 + 3 + 1)/6 = 4

Hence, the correct answer is 4 units and 7.1 units.

Q. 11 Consider the following data of three processes arrive at the same time.

Process BT
P1 250
P2 110
P3 150

Find the average waiting time if the Round Robin is used with a time quantum of 50 units.

  1. 258
  2. 260
  3. 256
  4. 257
   

Ans. (d)

Explanation: Round Robin with a time quantum of 50 units is used, The Gant chart will look like this:

P1 P2 P3 P1 P2 P3 P1 P2 P3 P1
0-50 50-100 100-150 150-200 200-250 250-300 300-350 350-360 360-410 410-510

We can find the completion time and waiting time from the above Gant chart.

CT of P1 = 510,        Waiting time of P1 = CT – BT = 510 – 250 = 260

CT of P2 = 360,        Waiting time of P2 = CT – BT = 360–110 = 250

CT of P3 = 410,        Waiting time of P3 = CT – BT = 410 – 150 = 260

Average Waiting Time = (260+250+260)/3 = 256.66667 = 257

Q.12   Which of the following algorithm is a non-preemptive CPU scheduling algorithm?

  1. Round Robin
  2. First Come First Serve
  3. Multilevel Queue Scheduling
  4. Multilevel Queue Scheduling with Feedback
   

Ans. (b)

Explanation: a) In Round-Robin, Preemption occurs when the time quantum expires.

b) In the First come first server, preemption does not occur; context switching happens only when a process completes its execution.

c) In the Multilevel Queue Scheduling, preemption occurs when a process with higher priority arrives.

d) In the Multilevel Queue Scheduling with feedback, preemption occurs when a process with higher priority arrives or when the quantum of the high priority queue expires

Q. 13  Four processes arrive at time zero. Their burst times are given below:

Process Burst Time
A 20
B 4
C 16
D 4

If the shortest job first is used, what is the response ratio of process C?

  1. 16
  2. 0.25
  3. 0.5
  4. 1
   

Ans. (b)

Explanation: Response ratio = Burst time / Turnaround time

The Gant chart for the following will look like this:

B D C A
0-4 4-8 8-24 24-44

We can find the completion and turnaround time for process C from the above Gant Chart.

CT = 24

TAT = CT – AT = 24 – 0 = 24

Response ratio = 8/24 = 0.25

Hence, the correct answer is 0.25.

Q. 14  Consider the following data of four processes arrive at time zero.

Process ID Priority ID Burst Time
P1 3 7
P2 1 2
P3 4 3
P4 2 4

Priority scheduling is used, and a higher priority ID means higher priority for that process. Calculate the average waiting time and average turnaround time.

  1. 8, 12
  2. 6.75, 10.75
  3. 6.25, 10.25
  4. 7.50, 8.25
   

Ans. (b)

Explanation: Given, priority scheduling is used. The Gant Chart for the same will look like this.

P3 P1 P4 P2
0-3 3-10 10-14 14-16

We can find the completion and turnaround time from the above Gant chart:

Process ID Priority ID AT BT CT TAT WT
P1 3 0 7 10 10 3
P2 1 0 2 16 16 14
P3 4 0 3 3 3 0
P4 2 0 4 14 14 10

Average TAT = (10+16+3+14)/4 = 10.75

Average WT = (3+14+0+10)/4 = 6.75

Hence, the correct answer is 6.75 and 10.75.

Q. 15  Round Robin is used on the given data. What is the completion time of process C if the time quantum is 2 units?

Process AT BT
A 4 6
B 3 8
C 2 5
D 1 4
  1. 17
  2. 18
  3. 19
  4. 24
   

Ans. (b)

Explanation: Given that, Round robin is used with a time quantum of 2 units. The Gant chart for the following will look like this.

D C B D A C B A C B A B
1-3 3-5 5-7 7-9 9-11 11-13 13-15 15-17 17-18 18-20 20-22 22-24

The completion time of process C is 18.

Deadlock

Q. 16  Which the following statement is/are False:

  1. Starvation could not occur on an OS with non-preemptive scheduling
  2. Starvation could occur on an OS with preemptive scheduling
  3. The deadlock could not occur on an OS with non-preemptive scheduling
  1. 1 and 2
  2. 1 and 3
  3. Only 1
  4. Only 3
   

Ans. (b)

Explanation: 1. Starvation could not occur on an OS with no-preemptive scheduling. (False)

2. Starvation could occur on an OS with preemptive scheduling (True)

3. The deadlock could not occur on an OS with non-preemptive scheduling (False)

Q. 17 Consider a system with four processes and four resources of the same type available. If each process requires a maximum of two resources. Which of the statement is correct?

  1. Deadlock may occur
  2. Thrashing
  3. Starvation may occur
  4. Deadlock never occurs in the system
   

Ans. (a)

Explanation: Given that, the system has four processes and three resources. Each process requires a maximum of 2 resources. Assume that each process holds one resource and request for the other one to start processing. Hence, the circular wait condition is satisfied, and the system turns to deadlock. Let P1, P2, P3, and P4 be the four processes.

MCQ on Operating System

Q. 18 Dissatisfying hold and wait to prevent deadlock causes

  1. Both deadlock and Starvation
  2. Both Deadlock and Starvation free
  3. Starvation may occur but deadlock-free
  4. Deadlock may happen, but starvation free
   

Ans. (c)

Explanation: By dissatisfying hold and wait, the process must get all the resources before execution and must release all the resources after completion. This causes starvation for other processes.

Q. 19 Two Concurrent processes A and B wants to use resource R1 and R2 in a mutually exclusive manner. Initially R1 and R2 are free. The statements of the processes are given below.

  Process A Process B
S1 While (R1 == Busy); While (R1 == Busy);
S2 Set R1 = Busy; Set R1 = Busy;
S3 While (R2 == Busy); While (R2 == Busy);
S4 Set R2 = Busy; Set R2 = Busy;
S5 Use R1 and R2 Use R1 and R2
S6 Set R1 = Free Set R1 = Free
S7 Set R2 = Free Set R2 = Free

Is mutual exclusion guaranteed for R1 and R2? If not then show a possible interleaving of the statements of P1 and P2 such that mutual exclusion is violated.

  1. Mutual Exclusion is not guaranteed
  2. Mutual Exclusion is guaranteed
  3. Can’t say
  4. None of the above
   

Ans. (a)

Explanation: Given that initially R1 and R2 are free. Now, consider process A run the statement 1 and context switch occur process B run the statement S1 and S2 and set the R1 = Busy and again context switch occurs. Now, Process A run the statement S2 and set the R1 = Busy which was already set by the process B. Following the same steps for the statements S3 and S4 for both the processes. After this, both the process tries to run S5 i.e., use R1 and R2 at the same time. Hence, Mutual Exclusion is not guaranteed.

Hence, the correct answer is option a.

Q. 20 Consider a system having n resources of the same type. These resources are shared by four processes P1, P2, P3, and P4 and they need a maximum of 4, 5, 3, and 7 resources, respectively. For what value of n the deadlock will never occur.

  1. 8
  2. 15
  3. 19
  4. 16
   

Ans. (d)

Explanation: Maximum requirements of each process are 4, 5, 3, and 7. Allocate the resources one less than the maximum requirement for each process.

Resources allocated to process

P1 = 3

P2 = 4

P3 = 2

P4 = 6 Allocated resource = 15, this may lead to deadlock. To prevent deadlock, we need to full fill the requirement of at least one process. For that, we need one more resource. Hence the value of n will be 16.

Q. 21 Consider a system having15 processes, and each process requires a maximum of 4 resources. If P is the maximum number of resources for the system to be in deadlock and Q is the minimum number of resources for the system to be free from deadlock.

Calculate the value of P and Q.

  1. P = 60 and Q = 61
  2. P = 45 and Q = 46
  3. P = 44 and Q = 46
  4. P = 46 and P = 45
   

Ans. (b)

Explanation: Given that there are 15 processes and each requires a maximum of 4 resources.

For the system to be in deadlock, we need to allocate resources one less than the maximum requirements.

P = no. of processes * (maximum requirement – 1)

P = 15 * 3 = 45

For the system to be deadlock-free, we need to full fill the requirement of at least one process.

Q = P + 1 = 46

Hence, b is the correct answer.

Q. 22Consider a system having 5 processes sharing 16 instances of a resource. The maximum need and current allocation of the resource are given below: (Question Type MSQ, i.e., more than one option can be correct)

Process Maximum Requirement Allocated
A 10 2
B 14 2
C 12 4
D 6 2
E 8 2

With reference to the current allocation, is the system safe? And if yes,then what is/are the correct sequences for the safe system?

  1. No
  2. Yes, D, E, C, B, and A
  3. Yes, D, E, A, C, and B
  4. Yes, D, E, C, A, and B
   

Ans. (b, c, and d)

Explanation: From the given data, we can find the current need and instances available

Process Maximum Requirement Allocated Current Need
A 10 2 8
B 14 2 12
C 12 4 8
D 6 2 4
E 8 2 6

Total instances = 16

Allocated = 12

Available = 16 – 12 = 4

At this stage, we can only full fill the requirement of process D. Allocating the available resources to process D after completing the execution it will release all the instances and we will have 6 instances. Here, we allocate it to process E and it will release all the instances after execution and we will have 8 instances. Here, we can allocate it to processes C and A both. On allocating the resources to process A, there will one safe sequence which is D, E, A, C, and B. On the other hand, when we allocate the resource to the process C, we will have two safe sequences which are D, E, C, A, and B and D, E, C, B, and A.

Hence, option b, c and d are correct.

Q.23 Consider a system having nine processes from P1 to P9 and seven resources from R1 to R7. The allocation of resources and requests are given below in the table.

Processes Allocated Request
P1 R4 R3, R2
P2 R5 R4
P3 - R2
P4 R1 R3
P5 R6 R2
P6 R3 R5
P7 - R3
P8 - R1
P9 R7 R6

With reference to the above data, which processes are deadlocked?

  1. P1, P2, and P3
  2. P3, P5, and P9
  3. P1, P2, and P6
  4. P1, P2, and P5
   

Ans. (c)

Explanation: We can clearly see this in the resource allocation graph given below. Processes P2, P2, and P6 form a circular graph. Here, the condition of circular wait is satisfied. Hence, c is the correct answer.

MCQ on Operating System

Q. 24 A system having four processes and 200 instances of a resource. The maximum demand and allocated instances are given below in the table.

Process Maximum need Allocated
A 100 60
B 80 40
C 80 x
D 60 y

For what value/s of x and y the system will be in deadlock? (Question type MSQs)

  1. x = 80 and y = 20
  2. x = 40 and y 30
  3. x = 60 and y = 20
  4. x = 50 and y = 30
   

Ans. (d)

Explanation: Taking the value of x = 50 and y = 30. Now, calculating the current need of each process and instances available.

Process Maximum need Allocated Current need
A 100 60 40
B 80 40 40
C 80 50 30
D 60 30 30

Instances allocated = 60+40+50+30 = 180

Instances available = 200-180 = 20

Here, We can full fill the demand of any process for x = 50 and y = 30. Hence, d is the correct answer.

Q. 25 Banker’s Algorithm is applied in a system for

  1. Deadlock Prevention
  2. Deadlock Avoidance
  3. Deadlock Resolution
  4. Deadlock Recovery
   

Ans. (b)

Explanation: The Banker’s algorithm is used for deadlock avoidance

Q. 26 Consider a system having four processes sharing N instances of a resource. The maximum requirements of each process are 7, 5, 9, and 12. What is the minimum value of N for which system will never be in deadlock?

  1. 33
  2. 32
  3. 29
  4. 30
   

Ans. (d)

Explanation: The minimum value of N = (7-1) + (5-1) + (9-1) + (12-1) + 1 = 30. Hence, the correct answer is option d.

Q. 27 Consider a system having four processes sharing three resources R1, R2 and R3. R1 has 6 instances, R2 has 11 instances and R3 has 8 instances. Suppose at time zero, following snapshot of the system has been taken.

Process

Allocated

Max. Need

Available

R1

R2

R3

R1

R2

R3

R1

R2

R3

P1

1

0

1

9

4

3

2

3

3

P2

2

1

0

3

2

2

P3

2

0

3

10

0

4

P4

4

2

1

6

2

3

With reference to above data. What are the possible safe sequences of processes? (Question type MSQs)

  1. P2, P4, P1, P3 and P2, P4, P3, P1
  2. P1, P4, P3, P2 and P1, P2, P3, P4
  3. P4, P2, P1, P3 and P4, P2, P3, P1
  4. None
   

Ans. (a) and (c)

Explanation: We can find the current need of each process from the above data by subtracting the allocated instances from maximum need.

Process

Current Need

Available

R1

R2

R3

R1

R2

R3

P1

8

4

2

2

3

3

P2

1

1

2

P3

8

0

1

P4

2

0

2

Here, We can full fill the demand of both P2 and P4 processes. So, there will be two orders P2, P4 and P4, P2. We can allocate either to P2 first or P4 first.

On allocating the resource to P2:

After complete execution of process P2 it will release all the instances.

Available Resources would be:

R1 R2 R3
4 4 3

Here we can only full fill the demand of process P4

After complete execution of P4. It will also release all the instances. And

Available resources would be

R1 R2 R3
8 6 4

Here, We can full fill the demand of process p1 and P3 both. So, it will depend on us to which process we are allocating the resources. And we will have two orders here to P1, P3 and P3, P1.

The possible safe sequences are (P2, P4, P1, P3), (P2, P4, P3, P1), (P4, P2, P1, P3), and (P4, P2, P3, P1). Hence, options a and c both are correct.

Q. 28 Consider a system with 4 processes P1, P2, P3, and P4 and 3 resources R1, R2, and R3. The maximum need and current allocation are given below in the table.

Process

Allocated

Maximum Need

Available

R1

R2

R3

R1

R2

R3

R1

R2

R3

P1

1

1

2

4

3

6

a

b

c

P2

0

1

1

2

1

3

P3

1

0

1

3

0

4

P4

1

1

1

4

1

2

Let X = a + b + c. What is the minimum value of X for which the system is safe?

  1. 4
  2. 5
  3. 3
  4. 9
   

Ans. (a)

Explanation: Calculating the current need of each process:

Process

Current Need

R1

R2

R3

P1

3

2

4

P2

2

0

2

P3

2

0

3

P4

3

0

1

Possible values of a, b, and c are (3, 0, 1), (2, 0, 2), (2, 0, 3) and (3, 2, 4)

Taking a = 3, b = 0, c = 1.

We can full fill the need of process P4.

After execution it will release all the resources.

Current Available: a = 3+1 = 4, b = 0+1 = 1, c = 1+1 = 2.

Now, we can full fill the demand of process P2.

After execution P2 will release all the resources.

Current available: a = 4+0 = 4, b = 1+1 = 2, c = 2+1 = 3

Here, we can full fill the demand of process P3.

After execution P3 will release all the resources.

Current available: a = 4+1 = 5, b = 2+0 = 2, c = 3+1 = 4

Now, we can full fill the demand of process P4.

Hence the minimum value of X = 3+0+1 = 4.

Q. 29 Consider a system with four processes P1, P2, P3, and P4 are sharing three resources R1, R2, and R3. The maximum need and current allocation is given below in the table:

Process

Allocated

Maximum Need

Available

R1

R2

R3

R1

R2

R3

R1

R2

R3

P1

2

1

1

6

3

4

a

b

c

P2

1

1

0

3

1

2

P3

1

0

1

4

0

3

P4

1

1

1

2

1

4

Which of the following options is/are correct? [Question Type MSQ]

  1. a = 2, b = 0, and c = 2, only one possible safe sequence
  2. a = 2, b = 1, and c = 2, only two possible safe sequences
  3. a = 1, b = 1, and c = 3, only two possible safe sequences
  4. None of the above
   

Ans. (a) and (b)

Explanation:Calculating the current need of each process

Process

Current Need

R1

R2

R3

P1

4

2

3

P2

2

0

2

P3

3

0

2

P4

1

0

3

Option (a) will give only one possible safe sequence which is P2, P3, P4, P1.

Option (b) will give only two possible safe sequences which are P2, P3, P1, P4 and P2, P3, P4, P1.

Option (c) will give only one possible safe sequence which is P4, P2, P3, P1.

Hence the correct answer is (a) and (b).

Q. 30 Consider a system with four processes and each process can maximum demands k instances of a resource to complete their execution. What is the minimum number of resources required to prevent the deadlock?

  1. 4k – 1
  2. 4k + 1
  3. 4k – 4
  4. 4k – 3
   

Ans. (d)

Explanation: To prevent deadlock allocate resources to each process one less than their maximum demand. After this full fill the demand of at least one process.

Minimum no. of resources required = (k-1) + (k-1) + (k-1) + (k-1) + 1 = 4k – 3. Hence, d is the correct answer.

Q. 31 The wait for graph is a deadlock detection algorithm that is applicable when _____________

  1. All resources have multiple instances
  2. All resources have a single instance
  3. A few resources have multiple instances
  4. None of the above
   

Ans.  (b)

Explanation: The wait for graph algorithm is only applicable when al the resources have only single instances and it can not work when the resources have multiple instances.

Q. 32 Which of the following is not involved in preventing the deadlock?

  1. No Mutual exclusion
  2. No “hold and wait”
  3. No circular wait
  4. No preemption
   

Ans. (d)

Explanation:To prevent deadlock, following are the necessary condition for deadlock:

  • Mutual Exclusion
  • Hold and Wait
  • Circular wait
  • No preemption

“No Preemption” not occurs to prevent deadlock.

Hence, d is the correct answer.

Process Synchronization

Q. 33 Consider two programs P1 and P2

S no. Process P1 Process P2
1 Void P1() Void P2()
2 { {
3 Wait(x1); Wait(x2);
4 p = p+1; q = q+1;
5 Wait(x2); Wait(x1);
6 Signal(x2); Signal(x1);
7 p = p-q; q = p+q;
8 Signal(x1); Signal(x2);
  } }

Here, x1 and x2 are two semaphore initially initialized to one and p and q are two shared variable. Which of the following option is correct for the above given data?

  1. Deadlock occurs
  2. Mutual Exclusion
  3. Progress
  4. No deadlock
   

Ans. (a)

Explanation:

Both the process will start running concurrently

On line number 3, process p1 will wait on x1, and will change the value of x1 = 0. Also process p2 will wait on x2, and will change the value of x2 = 0.

Both the process will enter in their critical section

On line number 4, both the processes p1 and p2 will infinitely wait on x2 and x1 respectively. Hence, the deadlock will occur.

Q. 34 Consider two programs A and B

Program A Program B
While (a); While (b);
{ {
b = 1; a = 1;
// Critical Section // critical section
a = 0; b = 0;
} }

Assume that the both the a and b were initialized to zero. Which of the given option is true for the above given Snippet?

  1. It satisfies Mutual exclusion but not progress
  2. It satisfies Progress but not Mutual exclusion
  3. It does not satisfy both mutual exclusion and progress
  4. It satisfies both mutual exclusion and progress
   

Ans. (b)

Explanation: As the a and b both are initialized to zero, both the processes can enter in the critical section at the same time hence, there is no mutual exclusion but it satisfies the progress.

Q. 35 Consider two processes A and B, their code snippet if given below

Process A Process B
Do { Do {
Flag[i] = true; Flag[j] = true;
Turn = B; Turn = A;
While(flag[j] and turn == B); While(flag[i] and turn == A);
// Critical section // Critical section
Flag[i] = false; Flag[j] = false;
// Remaining part // Remaining part
} while(1) } while(1)

If initially flag[i] = false and flag[j] = false, which of the following option is/are correct? [Question types MSQ]

  1. Achieves Mutual Exclusion
  2. Achieves Progress
  3. Involves busy waiting
  4. Do not achieve bounded waiting
   

Ans. (a), (b), and (c)

Explanation: The above question is based on the Peterson’s solution, where Mutual exclusion, bounded wait and progress is achieved but it involved busy waiting. Hence, option a, b and c are correct.

Q. 36 Peterson’s solution of process synchronization satisfies which of the following condition/s?

  1. Mutual Exclusion
  2. Progress
  3. Bounded wait
  4. All of the above
   

Ans. (d)

Explanation: The Peterson’s Solution of process synchronization satisfies mutual exclusion, progress and bounded wait but also involves busy wait.

Q. 37 Decker’s Algorithm of process synchronization satisfies the following condition

  1. Mutual Exclusion
  2. Progress
  3. Bounded wait
  4. Both a and c
   

Ans. (d)

Explanation:Decker’s Algorithm satisfies mutual exclusion and bounded wait but not progress.

Q. 38 The Lock variable method of process synchronization do not satisfy the following condition

  1. Mutual Exclusion
  2. Progress
  3. Bounded wait
  4. Both a and c
   

Ans. (d)

Explanation: The Lock Variable method only satisfies the condition of progress and do not satisfy mutual exclusion and bounded wait.

Q. 39 The test and set lock method do not satisfy which of the following condition?

  1. Mutual Exclusion
  2. Progress
  3. Bounded wait
  4. None of the above
   

Ans. (c)

Explanation: The test and set lock method satisfies mutual exclusion and progress and do not satisfy bounded wait.

Q. 40 Which of the following synchronization method satisfies mutual exclusion and bounded waiting but not progress?

  1. Peterson’s Solution
  2. Decker’s Algorithm
  3. Lock Variable
  4. Test and Set Lock Method
   

Ans. (b)

Explanation: a) Peterson’s solution satisfies all mutual exclusion, progress and bounded wait.

b) Decker’s Algorithm satisfies mutual exclusion and bounded wait but not progress.

c) Lock variable satisfies only progress not mutual exclusion and bounded wait.

d) Test and Set Lock variable satisfies mutual exclusion and progress but not bounded wait. Hence, the correct option is (b).

Q. 41 Starvation occurs in

  1. Binary semaphore
  2. Counting semaphore
  3. None
  4. Both
   

Ans. (a)

Explanation: In binary semaphore, only one process can enter in the critical section and there is not time limit on how long a process can be run. This makes other processes starve.

Q. 42 Consider a semaphore A, initialized with value 50. What should be the value of A when p() and v() functions is called on s for 23 and 11 times respectively.

  1. 38
  2. 16
  3. -16
  4. None of the above
   

Ans. (a)

Explanation:

P() refers to wait() which reduces the value of semaphore by 1 and v() refers to signal() which increase the value of semaphore by 1.

S = 50 – 23 + 11 = 38

Hence, (d) is the correct answer.

Q. 43 Which of the following process synchronization method is/are implemented in user mode?

  1. Peterson’s Solution
  2. Lock variable
  3. Strict Alternation
  4. All the above
   

Ans. (d)

Explanation: All the above methods are implemented in user mode as they do not require hardware support.

Q. 44 Define critical section

  1. A program segment where shared resources are accessed
  2. A program segment which is error free
  3. A program segment which is never executed
  4. None of the above
   

Ans. (a)

Explanation: Critical section is the program segment where the shared resources are accessed.

Q. 45 Consider the following programs

Program P1 Program P2
While (s == 0); While (s == 1);
{ {
// Critical Section // Critical Section
s = 0; s = 1;
} }

Here, s is the binary semaphore shared by both the processes. If s is initialized to zero, which of the following option is true?

  1. It satisfies Mutual Exclusion
  2. It satisfies Progress
  3. Both (a) and (b)
  4. None of the above
   

Ans. (a)

Explanation: It satisfies the mutual exclusion as only one process can enter in the critical section at a time. But due to strict alternation, it does not satisfy the progress.

Q. 46 Consider the following two process

Process P1 Process P2
While (true) { While (true) {
S1 = 1; S2 = 1;
While (S2 == 1) { While (S1 == 1) {
// Critical Section // Critical Section
S1 = 0; S2 = 0;
} }
} }

Here, S1 and S2 are two shared variables initially initialized to zero. Which of the following statement is true?

  1. No mutual exclusion and no deadlock
  2. Progress but not mutual exclusion
  3. Deadlock but not progress
  4. Mutual exclusion and no deadlock
   

Ans. (a)

Explanation: As both the processes can enter in their critical section at the same time. Hence, it does not satisfy mutual exclusion.

Q. 47 Assume that at a given instant the value of the semaphore is equal to the -n. Which of the following information can be deduced from the above statement?

  1. The number of processes present in the critical section is equal to n
  2. The number of processes blocked and waiting in the queue to access the critical section is equal to n
  3. The value of semaphore can’t be negative, it has only positive values
  4. None of the above
   

Ans. (b)

Explanation: The given statement clearly denotes that the number of blocked processes is equal to n. Hence, (b) is the correct answer.

Q. 48 Consider the two processes given below

Process A Process B
Wait(s1); Wait(s2);
Wait(s2); Wait(s1);
// Critical section // Critical Section
Signal(s1); Signal(s2);
Signal(s2); Signal(s1);

Here s1 and s2 are two binary semaphores initialized to 1. Which of the following options holds true for the execution of the above processes?

  1. Mutual exclusion
  2. Deadlock
  3. Starvation
  4. Multithreading
   

Ans. (b)

Explanation:On line one, process A waits on s1 and make s1 = 0 and preempted. Now, the process B waits on s2 and make s2 = 0. Here, both the semaphores are equal to zero. Hence, no process can enter in their critical section and deadlock occur.

Q. 49 Consider the two concurrent processes

Process P1 Process P2
Repeat forever Repeat forever
V(x); P(x);
// Critical Section // Critical Section
P(x); V(x);

Here, x is the shared semaphore and initialized to zero. Consider the following options:

  1. It is possible that the P1 can starve
  2. It is possible that the P2 can starve

Which of the option is/are true?

  1. Only I is true
  2. Only II is true
  3. Both I and II are true
  4. Both I and II are false
   

Ans. (c)

Explanation:Here, both the processes can run infinite number of times and make other program starve.

Q. 50 The critical section of other programs should not be executed while the critical section of another is being executed. What is this relation of processes called?

  1. Progress
  2. Mutual Exclusion
  3. Multiprogramming
  4. Multithreading
   

Ans. (b)

Explanation: Mutual exclusion – No two processes should be present in the critical section at the same time, i.e., only one process is allowed to enter in the critical section at a time. Hence, (b) is the correct answer.



ADVERTISEMENT
ADVERTISEMENT