π Preemptive Scheduling in Operating System (39 MCQs)
π From Operating System β’ 6. CPU Scheduling β’ 39 questions available
What is Preemptive Scheduling in Operating System?
Definition:
Preemptive scheduling allows the operating system to forcibly remove a running process from the CPU before it completes, typically when a higher priority process arrives or a time quantum expires.
Example:
In Round Robin scheduling, if Process X uses its full 10ms time quantum, the OS preempts it and switches to Process Y even if X has not finished its CPU burst.
Reason:
Preemption prevents any single process from monopolizing the CPU, ensuring fair resource distribution and guaranteeing bounded response times for interactive and real-time applications.
π All Preemptive Scheduling in Operating System MCQs
Q1. Under which circumstance does scheduling become unavoidable?
π Explanation: Scheduling is unavoidable when a process switches from running to waiting (due to I/O request or wait() call) because the CPU becomes idle. Unlike other circumstances, there is no choiceβthe system must select a new process for execution.
Q2. When a process terminates, what scheduling decision must be made?
π Explanation: When a process terminates, the CPU becomes available and the scheduler has no choice but to select a new process from the ready queue. This is one of the unavoidable scheduling circumstances.
Q3. What is nonpreemptive scheduling also called?
π Explanation: Nonpreemptive scheduling is also called cooperative scheduling because processes voluntarily release the CPU by terminating or switching to waiting state. The process cooperates with the scheduler by not holding the CPU indefinitely.
Q4. Which operating system was the first to introduce preemptive scheduling in the Windows family?
π Explanation: Windows 95 introduced preemptive scheduling in the Windows operating system family. Earlier versions like Windows 3.x used nonpreemptive scheduling. All subsequent Windows versions have used preemptive scheduling.
Q5. Under nonpreemptive scheduling, how does a process release the CPU?
π Explanation: In nonpreemptive scheduling, a process keeps the CPU until it releases it either by terminating or by switching to the waiting state. The process voluntarily gives up the CPU rather than being preempted by the scheduler.
Q6. What is a primary disadvantage of preemptive scheduling?
π Explanation: Preemptive scheduling can lead to race conditions when processes share data. If a process is preempted while updating shared data, another process may read inconsistent data, leading to data integrity problems and potential system failures.
Q7. Which scheduling approach does Mac OS X use?
π Explanation: Mac OS X uses preemptive scheduling. Previous versions of the Macintosh operating system relied on cooperative scheduling, but the OS X family adopted preemptive scheduling for improved responsiveness and multitasking capabilities.
Q8. What hardware feature is required for preemptive scheduling?
π Explanation: Preemptive scheduling requires a timer to generate interrupts at regular intervals, enabling the operating system to preempt running processes. Cooperative scheduling does not require this special hardware, making it usable on certain hardware platforms without a timer.
Q9. When scheduling occurs under circumstances 2 and 3, what type of scheduling is being used?
π Explanation: When scheduling decisions occur under circumstances 2 (running to ready) and 3 (waiting to ready), the system is using preemptive scheduling. Circumstances 1 and 4 characterize nonpreemptive scheduling where scheduling is forced by process state changes.
Q10. What problem can occur when a process is preempted during a system call?
π Explanation: If a process is preempted during a system call while modifying important kernel data structures, the kernel may access inconsistent data. This can lead to system instability or corruption. Operating systems must design kernels to handle or prevent such scenarios.
Q11. How do most UNIX versions handle potential preemption during system calls?
π Explanation: Most UNIX versions wait for a system call to complete or for an I/O block to occur before performing a context switch. This ensures kernel data structures remain consistent and simple, as the kernel won't preempt while data is in an inconsistent state.
Q12. What is the main limitation of the UNIX kernel-execution model regarding system calls?
π Explanation: The UNIX kernel-execution model, which waits for system calls to complete before context switching, is poor for real-time computing. Real-time tasks must complete within specific time frames, and this model can introduce unacceptable delays in task execution.
Q13. Why must interrupts not always be ignored by the kernel?
π Explanation: The kernel must accept interrupts at almost all times because ignoring them can result in lost input or overwritten output. Interrupts are crucial for handling I/O operations, and failing to process them leads to data loss or system errors.
Q14. How does the kernel protect critical sections from interrupt interference?
π Explanation: The kernel protects critical sections by disabling interrupts at entry and reenabling them at exit. This ensures that these sections are not accessed concurrently by multiple processes or interrupt handlers, preventing data corruption.
Q15. What characteristic do critical sections that disable interrupts typically have?
π Explanation: Critical sections that disable interrupts typically contain few instructions and do not occur very often. This is by design to minimize the time interrupts are disabled, maintaining system responsiveness while protecting sensitive kernel operations.
Q16. Which scenario would NOT cause a context switch under nonpreemptive scheduling?
π Explanation: Under nonpreemptive scheduling, a timer interrupt does not cause a context switch unless the process voluntarily gives up the CPU. Preemptive scheduling is required for timer-based context switching. Nonpreemptive systems rely on processes to release the CPU.
Q17. What happens to a process's state during preemption?
π Explanation: During preemption, the process moves from the running state to the ready state. The process is not terminated but is placed back in the ready queue, allowing the CPU to be allocated to another process. This is characteristic of preemptive scheduling.
Q18. When two processes share data and one is preempted mid-update, what data issue arises?
π Explanation: When a process is preempted while updating shared data, another process may read the data in an inconsistent state. This race condition occurs because the update operation was not atomic, leading to potential data corruption if the second process uses the inconsistent data.
Q19. What is the primary challenge when designing the kernel for preemptive scheduling?
π Explanation: The primary challenge is ensuring kernel data structure consistency during preemption. The kernel must be designed to handle preemption during system calls without corrupting data, requiring careful synchronization mechanisms and atomic operations.
Q20. Why can't the kernel simply ignore all interrupts to protect critical sections?
π Explanation: Ignoring all interrupts would cause input loss or output overwritten. Since interrupts are essential for handling I/O operations, the kernel must accept them at almost all times. Instead, it selectively disables interrupts only during short critical sections to maintain system functionality.
Q21. What hardware requirement makes cooperative scheduling preferable on some platforms?
π Explanation: Cooperative scheduling does not require special hardware like a timer, making it usable on hardware platforms without such capabilities. This is the only scheduling method that can work on certain hardware platforms, making it essential for resource-constrained or legacy systems.
Q22. How does preemptive scheduling improve over cooperative scheduling in Windows 95?
π Explanation: Preemptive scheduling in Windows 95 improved responsiveness and multitasking capabilities. Unlike cooperative scheduling where processes must voluntarily release the CPU, preemptive scheduling allows the system to ensure fair CPU allocation and immediate response to high-priority tasks.
Q23. What happens if a system call modifies kernel data structures and a preemption occurs?
π Explanation: If a system call modifies kernel data structures and is preempted, the kernel may have inconsistent data. This can lead to corruption if another process or interrupt handler accesses the same structures before the update is complete, potentially causing system instability.
Q24. In real-time systems, why is the UNIX kernel model inappropriate?
π Explanation: The UNIX kernel model, which waits for system calls to complete before context switching, introduces unpredictable delays. Real-time systems require deterministic behavior where tasks must complete within specific time frames, making this model unsuitable for meeting timing constraints.
Q25. Which of the following is a valid reason for disabling interrupts in the kernel?
π Explanation: Disabling interrupts protects critical sections of code from concurrent access. During these protected sections, the kernel can safely modify shared data structures without risking interruption or data corruption, ensuring system stability and consistency.
Q26. What is the relationship between preemptive scheduling and timer interrupts?
π Explanation: Timer interrupts are the mechanism through which preemptive scheduling occurs. When a timer interrupt fires, the scheduler can preempt the current process and select another process for execution, enabling time-sharing and fair CPU allocation among processes.
Q27. Why does cooperative scheduling require processes to behave well?
π Explanation: Cooperative scheduling requires processes to behave well because a process that holds the CPU without releasing it can starve other processes. If a process enters an infinite loop or delays releasing the CPU, the entire system becomes unresponsive, highlighting the need for well-behaved processes.
Q28. When a process switches from waiting to ready state, what scheduling decision is made?
π Explanation: When a process switches from waiting to ready state, the scheduler has a choice to preempt the current process. In preemptive scheduling, this is one of the conditions where scheduling may occur, potentially selecting the newly ready process based on scheduling criteria.
Q29. What prevents race conditions in preemptive scheduling?
π Explanation: Race conditions in preemptive scheduling are prevented by disabling preemption during critical sections where shared data is accessed. This ensures atomicity of operations, preventing other processes from accessing inconsistent data during updates, maintaining data integrity.
Q30. How does the kernel determine which sections of code require interrupt protection?
π Explanation: Only sections of code that access shared data structures or critical kernel resources require interrupt protection. These sections disable interrupts briefly at entry and reenable them at exit, protecting only the minimal necessary code to maintain system responsiveness.
Q31. What is the role of the timer in preemptive scheduling?
π Explanation: The timer in preemptive scheduling generates periodic interrupts that allow the scheduler to take control and potentially preempt the currently running process. This ensures no process monopolizes the CPU and enables time-sharing among multiple processes.
Q32. In cooperative scheduling, what happens if a process enters an infinite loop?
π Explanation: In cooperative scheduling, if a process enters an infinite loop, the system becomes unresponsive because the process never voluntarily releases the CPU. This is a fundamental weakness of cooperative scheduling that preemptive scheduling addresses through timer interrupts.
Q33. What data structure inconsistency can occur during preemption in system calls?
π Explanation: During preemption in system calls, I/O queues may become corrupted if the kernel is updating queue structures. If a process is preempted mid-update, queue pointers may be inconsistent, leading to data structure corruption and potential system crashes.
Q34. How do modern operating systems handle kernel preemption?
π Explanation: Modern operating systems use various approaches to handle kernel preemption including preemption points where context switches can safely occur, disabling preemption during critical operations, and leveraging hardware support for safe preemption mechanisms.
Q35. What is the key difference between preemptive and nonpreemptive scheduling regarding process control?
π Explanation: Preemptive scheduling gives processes less CPU control (they can be interrupted at any time), nonpreemptive scheduling requires process cooperation to release the CPU, and preemptive scheduling requires timer hardware for interrupts. These are fundamental distinctions between the two approaches.
Q36. Why might an operating system designer choose nonpreemptive scheduling?
π Explanation: Nonpreemptive scheduling reduces overhead from context switching because processes voluntarily release the CPU, eliminating the need for timer-based preemption interrupts. This simpler approach is beneficial for systems with minimal multitasking requirements or resource-constrained environments.
Q37. What is the impact of preemptive scheduling on real-time systems?
π Explanation: Preemptive scheduling can introduce unpredictable delays in real-time systems due to context switching overhead and scheduling decisions. While beneficial for general-purpose systems, real-time applications require deterministic scheduling, making preemption challenging to manage predictably.
Q38. How does Windows 95 differ from Windows 3.x regarding process management?
π Explanation: Windows 95 introduced preemptive scheduling, making it fundamentally different from Windows 3.x which used cooperative scheduling. This improvement allowed better multitasking, system responsiveness, and prevented processes from monopolizing the CPU.
Q39. What condition would prevent preemptive scheduling from being used?
π Explanation: Preemptive scheduling requires timer hardware to generate interrupts. Without a timer, cooperative scheduling becomes the only viable method because the operating system cannot interrupt processes to enforce time-sharing or preemption decisions.