📝 Priority Scheduling Algorithm in Operating System (50 MCQs)
📖 From Operating System • 6. CPU Scheduling • 50 questions available
What is Priority Scheduling Algorithm in Operating System?
Definition:
Priority scheduling assigns each process a priority integer and allocates the CPU to the process with the highest priority, potentially causing starvation for low-priority processes.
Example:
A system process with priority 1 always preempts a user application with priority 10, but if no high-priority work exists, the user app eventually runs.
Reason:
This approach allows the OS to enforce importance hierarchies and meet diverse service requirements, though aging mechanisms must be implemented to prevent indefinite blocking of low-priority processes.
📝 All Priority Scheduling Algorithm in Operating System MCQs
Q1. What is the fundamental principle of priority scheduling?
📖 Explanation: Priority scheduling allocates the CPU to the highest-priority process. Each process has an associated priority, and the scheduler always selects the ready process with the highest priority. Equal-priority processes are scheduled in FCFS order.
Q2. How does SJF relate to priority scheduling?
📖 Explanation: SJF is a special case of priority scheduling where priority is the inverse of the next CPU burst. A shorter CPU burst means higher priority (since it's the inverse), and longer bursts mean lower priority, making SJF a priority-based algorithm.
Q3. In priority scheduling with equal priorities, how are processes scheduled?
📖 Explanation: When processes have equal priorities, they are scheduled in FCFS order. This maintains fairness among equal-priority processes by serving them in arrival order, preventing any equal-priority process from being favored over another.
Q4. What does the term 'priority' generally indicate in scheduling?
📖 Explanation: Priority indicates the relative importance or urgency of a process. Higher priority processes get CPU access before lower priority ones. The priority can be based on various factors like time limits, memory requirements, or external importance.
Q5. If priorities range from 0 to 7, and lower numbers represent higher priority, what does priority 0 indicate?
📖 Explanation: When lower numbers represent higher priority, priority 0 indicates the highest possible priority. This convention varies across systems, but in this text, we assume lower numbers mean higher priority. Priority 7 would be the lowest priority.
Q6. What is a major problem with priority scheduling algorithms?
📖 Explanation: The major problem with priority scheduling is indefinite blocking (starvation). Low-priority processes may wait indefinitely if a steady stream of higher-priority processes continuously arrives, preventing them from ever getting CPU time.
Q7. What is the solution to the starvation problem in priority scheduling?
📖 Explanation: Aging is the solution to starvation. It gradually increases the priority of processes that have waited a long time, ensuring that even low-priority processes eventually get CPU time. Without aging, low-priority processes could wait forever.
Q8. What is aging in the context of priority scheduling?
📖 Explanation: Aging gradually increases the priority of processes that have been waiting in the system for a long time. This prevents starvation by ensuring that even low-priority processes eventually receive CPU access as their priority increases over time.
Q9. For the priority scheduling example with P1(10,priority3), P2(1,p1), P3(2,p4), P4(1,p5), P5(5,p2), what is the average waiting time?
📖 Explanation: Priority order (lower number = higher priority): P2(p1), P5(p2), P1(p3), P3(p4), P4(p5). Waiting times: P2=0, P5=1, P1=6, P3=16, P4=18. Average = (0+1+6+16+18)/5 = 41/5 = 8.2ms. This demonstrates how priority order affects waiting times.
Q10. What is the waiting time for P3 in the priority scheduling example?
📖 Explanation: Priority order: P2(1ms), P5(5ms), P1(10ms), P3(2ms), P4(1ms). P3 waits for P2(1) + P5(5) + P1(10) = 16ms. P3's burst is 2ms, and it completes at 18ms. The waiting time calculation is the sum of all higher-priority processes' bursts.
Q11. What is the difference between preemptive and nonpreemptive priority scheduling?
📖 Explanation: In preemptive priority scheduling, a newly arrived process with higher priority than the currently running process will preempt the CPU. In nonpreemptive priority scheduling, the current process continues even if a higher-priority process arrives, and the new process is simply placed at the head of the ready queue.
Q12. In nonpreemptive priority scheduling, what happens when a higher-priority process arrives?
📖 Explanation: In nonpreemptive priority scheduling, when a higher-priority process arrives, it cannot preempt the currently running process. Instead, it is placed at the head of the ready queue and will run as soon as the current process completes its burst.
Q13. What is the purpose of using lower numbers to represent higher priority in this text?
📖 Explanation: Using lower numbers to represent higher priority is a convention adopted in this text to avoid confusion. Different systems use different conventions (some use low numbers for low priority), so establishing a consistent convention is important for clear understanding.
Q14. Which of the following is an example of an internally defined priority?
📖 Explanation: Internally defined priorities use measurable quantities within the operating system. Time limits, memory requirements, number of open files, and I/O-to-CPU burst ratio are examples of internal priority factors. External factors include departmental sponsorship, funding, and political considerations.
Q15. Which of the following is an example of an externally defined priority?
📖 Explanation: External priorities are set by criteria outside the operating system, including the importance of the process, funding amounts, department sponsorship, and political factors. Internal priorities are based on measurable system quantities like time limits, memory, and I/O ratios.
Q16. What is the relationship between CPU burst length and priority in SJF?
📖 Explanation: In SJF, priority is the inverse of the CPU burst length. Smaller burst means higher priority (since the process will complete faster), and larger burst means lower priority. This is why SJF is considered a special case of priority scheduling.
Q17. What is the waiting time for P4 in the priority scheduling example?
📖 Explanation: Priority order: P2(p1), P5(p2), P1(p3), P3(p4), P4(p5). P4 waits for P2(1) + P5(5) + P1(10) + P3(2) = 18ms. P4's burst is 1ms, and it completes at 19ms. This is the longest waiting time because P4 has the lowest priority.
Q18. What is the waiting time for P2 in the priority scheduling example?
📖 Explanation: P2 has the highest priority (priority 1) and runs first. Since it arrives at time 0, its waiting time is 0ms. P2's burst is 1ms, completing at time 1. This is the minimum possible waiting time, reserved for the highest-priority process.
Q19. What happens when a low-priority process waits indefinitely in priority scheduling?
📖 Explanation: When a low-priority process waits indefinitely due to a continuous stream of higher-priority processes, this is called starvation or indefinite blocking. The process remains ready to run but never receives CPU time, potentially waiting forever.
Q20. In priority scheduling with priorities 0-127 (0=highest), if aging increases priority by 1 every 15 minutes, how long for a priority-127 process to reach priority 0?
📖 Explanation: To age from priority 127 to priority 0, the process needs its priority increased 127 times (127 to 0 = 127 increments). At 15 minutes per increment, total time = 127 × 15 = 1905 minutes = 31.75 hours. This demonstrates that while aging eventually works, it can take a very long time.
Q21. What would be the effect of a steady stream of higher-priority processes on a low-priority process?
📖 Explanation: A steady stream of higher-priority processes continuously takes the CPU, preventing the low-priority process from ever running. This is the classic starvation scenario that aging is designed to prevent by gradually increasing the priority of waiting processes.
Q22. What is the total time for a priority-100 process to reach priority 0 with aging increasing priority by 1 every 15 minutes?
📖 Explanation: To age from priority 100 to priority 0, the process needs 100 priority increments. At 15 minutes per increment, total time = 100 × 15 = 1500 minutes = 25 hours. This shows that higher initial priorities (lower numbers) need less time to reach the highest priority.
Q23. In the priority scheduling example, what is the completion time for P5?
📖 Explanation: Priority order: P2(1ms, runs 0-1), P5(5ms, runs 1-6). P5 completes at 6ms. P5 has priority 2, so it runs after P2 but before P1, P3, and P4. The completion time is 1ms (P2) + 5ms (P5) = 6ms.
Q24. What is the completion time for P3 in the priority scheduling example?
📖 Explanation: Priority order: P2(1ms, 0-1), P5(5ms, 1-6), P1(10ms, 6-16), P3(2ms, 16-18). P3 completes at 18ms. P3 waits for all higher-priority processes (P2, P5, P1) totaling 16ms of waiting time, then executes for 2ms.
Q25. What is the primary advantage of preemptive priority scheduling?
📖 Explanation: Preemptive priority scheduling can respond immediately when a higher-priority process arrives by preempting the current process. This reduces response time for high-priority processes. However, it increases context switching overhead compared to nonpreemptive priority scheduling.
Q26. What is the primary disadvantage of preemptive priority scheduling?
📖 Explanation: Preemptive priority scheduling increases context switching overhead because processes can be interrupted mid-burst when higher-priority processes arrive. This overhead can reduce system performance, especially in systems with frequent priority changes.
Q27. If aging increases priority by 1 every 15 minutes, how long for a priority-63 process to reach priority 0?
📖 Explanation: A priority-63 process needs 63 priority increments to reach priority 0 (63 to 0 = 63 increments). At 15 minutes per increment, total time = 63 × 15 = 945 minutes = 15.75 hours. This illustrates the time investment needed to guarantee service for low-priority processes.
Q28. What is the relationship between priority and CPU burst in SJF?
📖 Explanation: In SJF, priority is inversely related to CPU burst. As the CPU burst increases, the priority decreases (since priority = 1/burst). This inverse relationship is why SJF always selects the shortest next CPU burst, implementing priority scheduling with dynamically assigned priorities.
Q29. What is the waiting time for a process with the highest priority in priority scheduling?
📖 Explanation: The highest-priority process always runs first (or immediately if preemptive). If it arrives at time 0, its waiting time is 0ms. If it arrives later, its waiting time is the time until it gets the CPU, but it will always have the shortest possible waiting time among all processes.
Q30. What is the total CPU time consumed before P1 starts in the priority scheduling example?
📖 Explanation: P1 has priority 3. Before P1 can run, P2(priority 1) and P5(priority 2) must run. P2 takes 1ms, P5 takes 5ms, total = 6ms. P1 starts at time 6. This total is the sum of all higher-priority processes' burst times.
Q31. What is the completion time for P4 in the priority scheduling example?
📖 Explanation: Priority order: P2(0-1), P5(1-6), P1(6-16), P3(16-18), P4(18-19). P4 completes at 19ms. P4 has the lowest priority (priority 5), so it runs last. Its completion time equals the sum of all processes' bursts: 1+5+10+2+1 = 19ms.
Q32. How does aging prevent starvation in priority scheduling?
📖 Explanation: Aging gradually increases the priority of processes that have been waiting a long time. This ensures that even the lowest-priority processes will eventually have their priority raised high enough to get CPU time, thus preventing indefinite starvation.
Q33. What would happen if aging were not used in a priority scheduling system?
📖 Explanation: Without aging, low-priority processes could starve indefinitely if a continuous stream of higher-priority processes arrives. This is the classic indefinite blocking problem that aging was designed to solve. Starvation can lead to low-priority processes never completing.
Q34. What is the maximum waiting time for any process in the priority scheduling example?
📖 Explanation: P4 has the maximum waiting time of 18ms. P4 has priority 5 (lowest) and waits for P2(1), P5(5), P1(10), P3(2) = 18ms. This demonstrates the potential unfairness of priority scheduling without aging, where low-priority processes can wait excessively long.
Q35. What is the completion time for P1 in the priority scheduling example?
📖 Explanation: Priority order: P2(0-1), P5(1-6), P1(6-16). P1 completes at 16ms. P1's burst is 10ms, and it waits 6ms for P2 and P5. Total completion time = 6ms waiting + 10ms execution = 16ms. P1 has priority 3, so it runs after P2 and P5.
Q36. What is the effect of using internally defined priorities on scheduling?
📖 Explanation: Internally defined priorities use measurable quantities within the system, such as time limits, memory requirements, number of open files, and I/O-to-CPU burst ratios. This allows the operating system to automatically assign priorities based on process characteristics without external intervention.
Q37. Which scheduling approach is a special case of priority scheduling where priority is inversely related to CPU burst length?
📖 Explanation: SJF is a special case of priority scheduling where priority is the inverse of the CPU burst length. This relationship makes SJF a priority algorithm where shorter bursts have higher priority, implementing the same concept but with dynamically calculated priorities.
Q38. If priorities range from 0 (low) to 255 (high), and aging increases priority by 1 every 10 minutes, how long for a priority-0 process to reach priority 100?
📖 Explanation: To go from priority 0 to priority 100, the process needs 100 priority increments. At 10 minutes per increment, total time = 100 × 10 = 1000 minutes = 16.67 hours. This demonstrates the time required for a low-priority process to achieve a moderate priority level.
Q39. What is the total time for all processes in the priority scheduling example?
📖 Explanation: The total time (makespan) is the sum of all bursts: P2(1) + P5(5) + P1(10) + P3(2) + P4(1) = 19ms. This is also the completion time of the last process, P4. The schedule runs without idle time from 0 to 19ms.
Q40. What is the main tradeoff in preemptive priority scheduling?
📖 Explanation: Preemptive priority scheduling improves responsiveness to high-priority processes but increases context switching overhead. This tradeoff means systems must balance the need for quick response to high-priority tasks against the overhead of frequent context switches.
Q41. What is the average waiting time for a process that has the lowest priority in a set of 5 processes?
📖 Explanation: The lowest-priority process waits for all higher-priority processes to complete before running. Its waiting time equals the sum of the burst times of all higher-priority processes. In the example, P4 (lowest priority) waited 18ms for P2, P5, P1, and P3 to complete.
Q42. What is the effect of external priorities on scheduling decisions?
📖 Explanation: External priorities are based on factors outside the operating system, including the importance of the process, funding amounts, department sponsorship, and political considerations. These can introduce arbitrary or political factors into scheduling decisions.
Q43. If aging increases priority by 2 every 15 minutes, how long for a priority-100 process to reach priority 0?
📖 Explanation: A priority-100 process needs 100 priority increments to reach 0. At 2 increments every 15 minutes, each increment takes 7.5 minutes. Total time = 100 × 7.5 = 750 minutes = 12.5 hours. This shows that faster aging rates reduce the time to prevent starvation.
Q44. What is the waiting time for P5 in the priority scheduling example?
📖 Explanation: P5 has priority 2. It waits for P2(priority 1) only. P2 has a burst of 1ms, so P5's waiting time is 1ms. P5 runs from time 1 to time 6. Its waiting time is not its priority but the sum of bursts of higher-priority processes (P2 only).
Q45. What is the average waiting time for processes P1(5,p2), P2(3,p4), P3(8,p1), P4(2,p3) with priority scheduling (lower number = higher priority)?
📖 Explanation: Priority order: P3(p1,8ms), P1(p2,5ms), P4(p3,2ms), P2(p4,3ms). Waiting times: P3=0, P1=8, P4=13, P2=15. Sum=0+8+13+15=36. Average=36/4=9ms. The closest option is 10ms (B). Let me recalc: P3 0-8, P1 8-13, P4 13-15, P2 15-18. Waiting: P3=0, P1=8, P4=13, P2=15. Sum=36, avg=9. Closest is B (10ms).
Q46. What would be the effect of allowing user-defined priorities in a system?
📖 Explanation: User-defined priorities can lead to unfairness and starvation if users assign priorities arbitrarily. Without proper controls, high-priority processes could monopolize the CPU, and low-priority processes could starve. This is why systems often control or limit user priority assignments.
Q47. What is the relationship between the number of priority levels and the potential for starvation?
📖 Explanation: More priority levels increase the potential for starvation because there are more levels where processes can get stuck. A low-priority process at level 255 in a 0-255 system has many higher-priority levels that can continuously arrive, potentially delaying it indefinitely.
Q48. How does nonpreemptive priority scheduling differ from preemptive priority scheduling in terms of process interruption?
📖 Explanation: Nonpreemptive priority scheduling never interrupts a running process, even if a higher-priority process arrives. The running process continues until it completes its burst or requests I/O. Preemptive priority scheduling, by contrast, interrupts the running process when a higher-priority process arrives.
Q49. What is the completion time for the last process in the priority scheduling example with P1(10,p3), P2(1,p1), P3(2,p4), P4(1,p5), P5(5,p2)?
📖 Explanation: The last process is P4 with priority 5 (lowest). It completes at 19ms, which is the sum of all process bursts: 10+1+2+1+5 = 19ms. This makespan is determined by the total work to be done, regardless of scheduling order.
Q50. What is the key difference between internal and external priorities?
📖 Explanation: Internal priorities use measurable system quantities like time limits, memory requirements, and I/O ratios. External priorities use outside criteria like departmental importance, funding, or political factors. Internal priorities are technically based, while external can be arbitrary.