📝 CPU scheduling and Virtualization (13 MCQs)
Scheduling Virtual CPUs on Physical Processors
CPU scheduling in virtualisation determines how virtual CPUs belonging to guest operating systems receive execution time on physical processor cores. The hypervisor maintains runnable virtual CPU contexts and selects which ones execute. Guest operating systems may also schedule their own processes within virtual CPUs, creating two scheduling levels that influence application response time and overall host utilisation.
Why Multiple Guests Compete for CPU Capacity
A physical host may run more virtual CPUs than it has physical cores. When many guests demand processor time simultaneously, the hypervisor must share limited capacity. Uncontrolled allocation can cause long waiting periods, reduce responsiveness, and allow one busy guest to affect other workloads on the same host.
Hypervisor Scheduling and Guest Process Scheduling
The hypervisor schedules runnable virtual CPUs onto physical cores according to its policy, resource limits, and priorities. Inside each guest, its own operating system schedules processes onto available virtual CPUs. The host scheduler may pre-empt a virtual CPU while the guest is running, delaying the guest's internal scheduling and execution progress.
Example of Virtual CPU Contention
A host has four physical cores and runs two guests, each configured with four virtual CPUs. If all eight virtual CPUs become runnable together, they cannot all execute simultaneously on the four cores. The hypervisor time-shares physical processing capacity, potentially increasing each guest's waiting time.
Overcommitment, Fairness and Latency
Virtual CPU overcommitment allows flexible allocation but can create contention when workloads peak together. Scheduling policies may use shares, reservations, limits, and priorities to balance fairness and performance. Excessive virtual CPU counts do not guarantee more throughput and may increase scheduling overhead, while CPU-ready delays can make an otherwise lightly loaded guest appear slow.
Misconceptions About Virtual CPU Scheduling
'One virtual CPU always equals one physical core' ignores time-sharing and overcommitment. 'The guest scheduler controls the physical processor directly' overlooks hypervisor scheduling. 'Adding virtual CPUs always improves application speed' is false when physical capacity is saturated or the workload cannot use additional parallelism.
Exam Focus: Two Level CPU Scheduling
Distinguish guest-level process scheduling from hypervisor-level virtual CPU scheduling. Given physical core and virtual CPU counts, determine whether overcommitment exists. Explain how a runnable guest can still wait for physical CPU time, and evaluate the effects of reservations, limits, priorities, and workload contention.
Key Terms of Virtual CPU Scheduling
- vCPU - Virtual processor assigned to a guest.
- Physical core - Actual processor execution unit.
- Overcommitment - Assigning more virtual capacity than physical capacity.
- CPU ready time - Time a vCPU waits for execution.
- Reservation - Guaranteed portion of processor capacity.
📝 All CPU scheduling and Virtualization MCQs
Q1. What is the primary purpose of CPU scheduling in an operating system?
📖 Explanation: The correct answer is B because CPU scheduling decides which process receives the CPU at any given moment, directly influencing system throughput and responsiveness. Option A describes memory management, C describes disk I/O management, and D describes networking tasks, none of which are the scheduler’s role. Recognizing this helps students understand why effective scheduling is essential for multitasking and overall system performance.
Q2. Which statement best describes a preemptive CPU scheduling algorithm?
📖 Explanation: Answer B is correct because preemptive algorithms can interrupt a running process, allowing higher‑priority or time‑critical tasks to run immediately. Option A describes non‑preemptive behavior, C limits scheduling to a specific class of processes, and D suggests human control, which is not how OS schedulers operate. Knowing this distinction clarifies why preemptive scheduling improves responsiveness in interactive environments.
Q3. Three processes have CPU bursts of 10 ms, 4 ms, and 6 ms respectively. Using Round‑Robin with a 4 ms quantum, what is the average waiting time?
📖 Explanation: The correct answer is C. By simulating Round‑Robin, the waiting times are 10 ms for the first process, 4 ms for the second, and 12 ms for the third, giving an average of (10+4+12)/3 ≈ 8.67 ms. Options A, B, and D result from incorrect calculations or ignoring the quantum effect. This example shows how quantum size impacts waiting time, a key concept for designing efficient schedulers.
Q4. Why can priority inversion cause performance problems in a preemptive system?
📖 Explanation: Answer A is correct because when a low‑priority task holds a resource needed by a high‑priority task, the high‑priority task must wait, reducing responsiveness. Options B and C misrepresent how priorities affect scheduling, and D is false because inversion can happen in preemptive environments. Understanding this helps students anticipate and mitigate such issues, for example by using priority inheritance protocols.
Q5. In a type 0 hypervisor with four partitions each assigned a dedicated CPU core, a new high‑priority VM must run on core 2 currently occupied by a low‑priority VM. Which scheduling approach should the hypervisor use to minimize latency?
📖 Explanation: The correct answer is B because preemptive priority scheduling allows the hypervisor to interrupt the low‑priority VM and allocate the core to the high‑priority VM immediately, reducing wait time. Options A and D would not allow interruption, and C would add unnecessary context switches without addressing priority. This scenario illustrates why preemptive priority mechanisms are vital for meeting real‑time requirements in virtualized environments.
Q6. A system receives an average of 5 processes per second, each requiring 0.1 seconds of CPU time. What is the CPU utilization?
📖 Explanation: Answer B is correct because utilization equals arrival rate times average service time : , or 50 %. Options A, C, and D result from misapplying the formula or using incorrect values. This calculation demonstrates how workload characteristics directly affect CPU load, a fundamental concept for capacity planning.
Q7. How does a multi‑level feedback queue (MLFQ) adapt to both interactive and CPU‑bound processes?
📖 Explanation: The correct answer is B because MLFQ lowers the priority of CPU‑intensive processes while raising the priority of I/O‑bound or interactive ones, allowing quick response for interactive tasks. Option A describes a static priority system, C ignores priority differentiation, and D describes Shortest Job First, not MLFQ. Recognizing this dynamic behavior helps students design schedulers that balance throughput and responsiveness.
Q8. Using Shortest Remaining Time First (SRTF), processes arrive as follows: at time 0, P A with burst 8 ms; at time 2 ms, P B with burst 4 ms; at time 4 ms, P C with burst 2 ms. What is the CPU allocation order from time 0 to 8 ms?
📖 Explanation: Answer A is correct. At 0–2 ms, A runs (remaining 6 ms). At 2 ms, B arrives with a shorter remaining time, preempting A, so B runs from 2–6 ms (remaining 0 ms). At 6 ms, C (remaining 2 ms) runs until 8 ms. Options B, C, and D misorder the preemptions or ignore the SRTF rule. This scenario highlights how SRTF continuously selects the process with the smallest remaining CPU burst, improving average waiting time.
Q9. Which algorithm guarantees the minimum average waiting time for a given set of processes?
📖 Explanation: The correct answer is B because Shortest Job First (SJF) always selects the shortest available CPU burst, minimizing total waiting time across all processes. FCFS (A) follows arrival order regardless of burst length, Round‑Robin (C) adds context‑switch overhead, and Priority (D) may not consider burst length. Understanding why SJF is optimal helps students appreciate trade‑offs between fairness and efficiency.
Q10. A host with 8 physical cores runs 12 virtual machines under a fair scheduler that equally shares CPU time. What fraction of a core does each VM receive?
📖 Explanation: Answer B is correct because each VM receives of a core when CPU time is divided equally. Option A (1/2) would require 16 VMs, C (3/4) would need fewer VMs, and D (1) would imply each VM gets a full core. This calculation shows how over‑commitment works in virtualized environments, affecting performance expectations.
Q11. What does the term “virtual machine sprawl” refer to?
📖 Explanation: The correct answer is B because virtual machine sprawl describes a situation where numerous VMs are created without proper tracking, leading to complexity in monitoring, security, and resource allocation. Option A describes hardware expansion, C describes cloning, and D describes memory allocation. Recognizing sprawl helps administrators implement policies to maintain control and efficiency.
Q12. In a type 0 hypervisor, three VMs share a single network card using time‑division multiplexing with a 5 ms quantum. Each VM generates a packet every 15 ms. Will any VM experience packet loss due to scheduling?
📖 Explanation: Answer B is correct: each VM receives a 5 ms slot every 15 ms, matching its packet generation interval, so packets can be transmitted without overlap, preventing loss. Option A misinterprets quantum length, C incorrectly assumes simultaneous transmission leads to collision, and D ignores the timing relationship. This illustrates how careful time‑division scheduling can avoid network contention.
Q13. How does preemptive scheduling improve system responsiveness compared to non‑preemptive scheduling?
📖 Explanation: The correct answer is A because preemptive scheduling can pause a CPU‑intensive task to give immediate CPU access to a higher‑priority or interactive task, reducing latency. Options B and D misrepresent scheduling goals, and C is false because preemptive scheduling actually introduces context switches. Understanding this benefit explains why many modern OSes prefer preemptive algorithms for interactive workloads.