CPU Scheduling · Operating System
37 questions · asked in 24 of 27 years (2000–2026)
MCQ 24 · MSQ 2 · NAT 111-mark 21 · 2-mark 16
2000Questions per year2026
Questions 31–35 of 37
Consider three CPU-intensive processes, which require 10,20 and 30 time units and arrive at times 0,2, and 6, respectively. How many context switches are needed if the operating system implements a shortes remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end
Answer: (B)
Shortest remaining time first (SRTF) always runs the process with the least time left. The Gantt chart:
- : only is present, so it runs.
- : arrives with 20. has 8 left, which is less, so keeps running (no switch).
- : arrives with 30. has 4 left, so it keeps running (no switch).
- : ends. (20) is shorter than (30), so runs. This is switch 1.
- : ends and runs until 60. This is switch 2.
The switch at time 0 and the end at 60 are not counted, so there are 2 context switches.
Answer: (B)
- : only is present, so it runs.
- : arrives with 20. has 8 left, which is less, so keeps running (no switch).
- : arrives with 30. has 4 left, so it keeps running (no switch).
- : ends. (20) is shorter than (30), so runs. This is switch 1.
- : ends and runs until 60. This is switch 2.
The switch at time 0 and the end at 60 are not counted, so there are 2 context switches.
Answer: (B)
We wish to schedule three processes P1, P2 and P3 on a uniprocessor system. The priorities, CPU time requirements and arrival times of the processes are as shown below.
We have a choice of preemptive or non-preemptive scheduling. In preemptive scheduling, a late-arriving higher priority process can preempt a currently running process with lower priority. In non-preemptive scheduling, a late-arriving higher priority process must wait for the currently executing process to complete before it can be scheduled on the processor.
What are the turnaround times (time from arrival till completion) of P2 using preemptive and non-preemptive scheduling respectively?
We have a choice of preemptive or non-preemptive scheduling. In preemptive scheduling, a late-arriving higher priority process can preempt a currently running process with lower priority. In non-preemptive scheduling, a late-arriving higher priority process must wait for the currently executing process to complete before it can be scheduled on the processor.
What are the turnaround times (time from arrival till completion) of P2 using preemptive and non-preemptive scheduling respectively?
Answer: (D)
Turnaround time = completion time minus arrival time.
Non-preemptive: arrives at 0 and runs 0 to 15. At 15, (priority 10) and (priority 9) are waiting, so runs 15 to 35. Then runs 35 to 45.
turnaround = sec.
Preemptive:
- 0 to 3: runs (12 sec left).
- 3 to 5: arrives with higher priority and runs (8 sec left).
- 5 to 25: arrives with the highest priority and runs to completion.
- 25 to 33: finishes.
- 33 to 45: finishes.
turnaround = sec.
So the turnaround times of are 30 sec (preemptive) and 42 sec (non-preemptive).
Answer: (D)
Non-preemptive: arrives at 0 and runs 0 to 15. At 15, (priority 10) and (priority 9) are waiting, so runs 15 to 35. Then runs 35 to 45.
turnaround = sec.
Preemptive:
- 0 to 3: runs (12 sec left).
- 3 to 5: arrives with higher priority and runs (8 sec left).
- 5 to 25: arrives with the highest priority and runs to completion.
- 25 to 33: finishes.
- 33 to 45: finishes.
turnaround = sec.
So the turnaround times of are 30 sec (preemptive) and 42 sec (non-preemptive).
Answer: (D)
Consider the following set of processes, with the arrival times and the CPU-burst times given in milliseconds.
What is the average turnaround time for these processes with the preemptive shortest remaining processing time first (SRPT) algorithm?
What is the average turnaround time for these processes with the preemptive shortest remaining processing time first (SRPT) algorithm?
Answer: (A)
SRPT always runs the process with the shortest remaining time, and a new arrival can pre-empt.
- : only is present, so it runs.
- : arrives with 3. has 4 left, so pre-empts it.
- : arrives with 3. has 2 left, so it continues.
- : ends. arrives with 1, so it is the shortest and runs. Waiting are (4 left) and (3).
- : ends. (3) is shorter than (4), so runs to 8.
- : runs to 12.
Completion times: , , , .
Turnaround time = completion time minus arrival time:
, , , .
Average = ms.
Answer: (A)
- : only is present, so it runs.
- : arrives with 3. has 4 left, so pre-empts it.
- : arrives with 3. has 2 left, so it continues.
- : ends. arrives with 1, so it is the shortest and runs. Waiting are (4 left) and (3).
- : ends. (3) is shorter than (4), so runs to 8.
- : runs to 12.
Completion times: , , , .
Turnaround time = completion time minus arrival time:
, , , .
Average = ms.
Answer: (A)
A uni-processor computer system only has two processes, both of which alternate 10 ms CPU bursts with 90 ms I/O bursts. Both the processes were created at nearly the same time. The I/O of both processes can proceed in parallel. Which of the following scheduling strategies will result in the least CPU utilizations (over a long period of time) for this system ?
Answer: (D)
CPU utilization CPU burst time / total time of one cycle.
FCFS:
Time 0-10: process 1 runs
Time 10-20: process 2 runs
Process 1 started its I/O at 10 and is back at 100, so time 100-110: process 1 runs, and 110-120: process 2 runs
...
So in every 100 ms the CPU is used for 20 ms, and the utilization
SRTF:
The CPU bursts are equal, so it is the same as FCFS: 20%.
Static priority:
If process 1 has the higher priority, the schedule is the same as FCFS. If process 2 has it, the schedule is the same with the two processes swapped. So the utilization stays at 20%.
Round Robin (quantum 5 ms):
Time 0-5: process 1 runs
Time 5-10: process 2 runs
Time 10-15: process 1 runs its second 5 ms and finishes its burst, so its 90 ms I/O runs from 15 to 105
Time 15-20: process 2 finishes its burst, and its I/O runs from 20 to 110
Time 105-110: process 1 runs again
Time 110-115: process 2 runs
...
Because the two bursts are cut into two slices each, process 1 ends its burst at 15 and so is back only at 105. The cycle is 105 ms, with 20 ms of CPU use: utilization
19.05% is less than 20%, so round robin gives the least utilization.
(Round robin with a time quantum of 10 ms would have made the CPU utilization the same for all the schedules.)
Answer: (D)
FCFS:
Time 0-10: process 1 runs
Time 10-20: process 2 runs
Process 1 started its I/O at 10 and is back at 100, so time 100-110: process 1 runs, and 110-120: process 2 runs
...
So in every 100 ms the CPU is used for 20 ms, and the utilization
SRTF:
The CPU bursts are equal, so it is the same as FCFS: 20%.
Static priority:
If process 1 has the higher priority, the schedule is the same as FCFS. If process 2 has it, the schedule is the same with the two processes swapped. So the utilization stays at 20%.
Round Robin (quantum 5 ms):
Time 0-5: process 1 runs
Time 5-10: process 2 runs
Time 10-15: process 1 runs its second 5 ms and finishes its burst, so its 90 ms I/O runs from 15 to 105
Time 15-20: process 2 finishes its burst, and its I/O runs from 20 to 110
Time 105-110: process 1 runs again
Time 110-115: process 2 runs
...
Because the two bursts are cut into two slices each, process 1 ends its burst at 15 and so is back only at 105. The cycle is 105 ms, with 20 ms of CPU use: utilization
19.05% is less than 20%, so round robin gives the least utilization.
(Round robin with a time quantum of 10 ms would have made the CPU utilization the same for all the schedules.)
Answer: (D)
Which combination of the following features will suffice to characterize an OS as a multi-programmed OS ?
(A)More than one program may be loaded into main memory at the same time for execution.
(B) If a program waits for certain events such as I/O, another program is immediately scheduled for execution.
(C) If the execution of a program terminates, another program is immediately scheduled for execution.
(A)More than one program may be loaded into main memory at the same time for execution.
(B) If a program waits for certain events such as I/O, another program is immediately scheduled for execution.
(C) If the execution of a program terminates, another program is immediately scheduled for execution.
Answer: (B)
Multiprogramming means that several programs are kept in memory at the same time, and the CPU is switched to another program whenever the current one cannot use it.
- (A) is needed: without more than one program in memory there is nothing to switch to.
- (B) is needed: this is what keeps the CPU busy while a program waits for I/O. With (A) alone, the CPU could sit idle during I/O.
- (C) is not needed: starting the next program after one ends also happens in a simple batch system that runs one program at a time. So it adds nothing that separates multiprogramming from other systems.
So (A) and (B) together are enough.
Answer: (B)
- (A) is needed: without more than one program in memory there is nothing to switch to.
- (B) is needed: this is what keeps the CPU busy while a program waits for I/O. With (A) alone, the CPU could sit idle during I/O.
- (C) is not needed: starting the next program after one ends also happens in a simple batch system that runs one program at a time. So it adds nothing that separates multiprogramming from other systems.
So (A) and (B) together are enough.
Answer: (B)
Keep practising
Topics in Operating System
System CallProcessThreadProcess SynchronizationDeadlock
CPU SchedulingYou are here
Disk SchedulingMemory ManagementFile Systems