🎓 BookMCQ
← Back to 6. CPU Scheduling

📝 Linux Scheduling (75 MCQs)

📖 From Operating System • 6. CPU Scheduling • 75 questions available

What is Linux Scheduling?

Definition:
Linux uses the Completely Fair Scheduler (CFS) implementing proportional share via virtual runtime vruntimevruntime, maintaining red-black trees sorted by vruntimevruntime to select the leftmost node with O(log n) complexity.

Example:
A nice=-5 process accumulates vruntime slower than a nice=10 process, receiving more CPU shares while still guaranteeing eventual execution for all runnable tasks.

Reason:
CFS replaces complex priority queues with a mathematically fair model that naturally handles varying loads without tuning, providing good interactivity and throughput for general-purpose desktop/server workloads.

16
Easy
39
Medium
20
Hard

📝 All Linux Scheduling MCQs

Q1. Which scheduler became the default Linux scheduling algorithm in release 2.6.23 of the kernel?

A.O(1) Scheduler
B.Completely Fair Scheduler (CFS) ✅
C.Traditional UNIX Scheduler
D.Real-Time Scheduler
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The Completely Fair Scheduler (CFS) became the default Linux scheduler in kernel version 2.6.23. It replaced the O(1) scheduler, which had been introduced in Version 2.5 to address the limitations of the traditional UNIX scheduler for SMP systems.

Q2. What was the primary limitation of the traditional UNIX scheduler that led to its replacement in Linux Version 2.5?

A.It did not adequately support systems with multiple processors ✅
B.It consumed too much memory
C.It was too complex to maintain
D.It did not support real-time processes
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The traditional UNIX scheduling algorithm was not designed for SMP systems, so it did not adequately support multiprocessor systems. This limitation, along with poor performance with a large number of runnable processes, led to the development of the O(1) scheduler.

Q3. What does the O(1) designation mean for the Linux scheduler introduced in Version 2.5?

A.It runs in constant time regardless of the number of tasks ✅
B.It can only schedule one task at a time
C.It uses a priority of 1 for all tasks
D.It schedules tasks in order of arrival
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The O(1) designation indicates that the scheduler runs in constant time (O(1) complexity). This means the time to select the next task to run does not depend on the number of tasks in the system, providing scalability for systems with many runnable processes.

Q4. Which scheduler provided increased support for SMP systems including processor affinity and load balancing?

A.Traditional UNIX Scheduler
B.O(1) Scheduler ✅
C.Completely Fair Scheduler (CFS)
D.Real-Time Scheduler
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The O(1) scheduler, introduced in Version 2.5, provided increased support for SMP systems. It included features like processor affinity (keeping processes on the same processor) and load balancing between processors, which were essential for efficient multiprocessor operation.

Q5. What was the main drawback of the O(1) scheduler in practice?

A.It did not support real-time processes
B.It led to poor response times for interactive processes ✅
C.It did not support SMP systems
D.It had poor performance with many tasks
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Although the O(1) scheduler delivered excellent performance on SMP systems, it led to poor response times for interactive processes common on desktop systems. This drawback was a key factor in the development of the Completely Fair Scheduler (CFS).

Q6. On what principle is the Linux scheduling system based?

A.Time quanta
B.Scheduling classes ✅
C.Processor affinity
D.Priority inheritance
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Linux scheduling is based on scheduling classes. Each class is assigned a specific priority, and the kernel can accommodate different scheduling algorithms based on the needs of the system and its processes by using different scheduling classes.

Q7. How many scheduling classes do standard Linux kernels implement?

A.One: CFS
B.Two: CFS and real-time ✅
C.Three: CFS, real-time, and batch
D.Four: CFS, real-time, FIFO, and RR
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Standard Linux kernels implement two scheduling classes: (1) a default scheduling class using the CFS scheduling algorithm and (2) a real-time scheduling class. New scheduling classes can be added as needed.

Q8. How does the CFS scheduler determine the proportion of CPU processing time for each task?

A.Based on the task's priority
B.Based on the nice value assigned to each task ✅
C.Based on the task's arrival time
D.Based on the task's memory usage
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: CFS assigns a proportion of CPU processing time to each task based on its nice value. The nice value ranges from −20 to +19, with lower nice values indicating higher relative priority and thus a higher proportion of CPU time.

Q9. What is the range of nice values in the Linux CFS scheduler?

A.-20 to +19 ✅
B.0 to 39
C.1 to 99
D.100 to 139
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Nice values range from −20 to +19 in the Linux CFS scheduler. A numerically lower nice value indicates a higher relative priority. The default nice value is 0. This range provides 40 distinct priority levels for normal (non-real-time) tasks.

Q10. What is the default nice value for a task in the Linux CFS scheduler?

A.-20
B.0 ✅
C.10
D.19
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The default nice value for a task is 0. A task can increase its nice value (e.g., from 0 to +10) to be 'nice' to other tasks by lowering its relative priority. The default value represents a neutral priority level.

Q11. What is targeted latency in the CFS scheduler?

A.The minimum time quantum for a task
B.The interval of time during which every runnable task should run at least once ✅
C.The maximum time a task can run before being preempted
D.The time taken to select the next task
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Targeted latency is an interval of time during which every runnable task should run at least once. CFS allocates proportions of CPU time from the value of targeted latency, ensuring fairness by giving each task a chance to run within this interval.

Q12. What is the purpose of the vruntime variable in the CFS scheduler?

A.To record the virtual run time of each task ✅
B.To store the nice value of each task
C.To track the memory usage of each task
D.To record the number of context switches
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The vruntime variable records how long each task has run. It is associated with a decay factor based on the task's priority: lower-priority tasks have higher rates of decay, meaning their vruntime increases faster than higher-priority tasks for the same actual run time.

Q13. How does the CFS scheduler decide which task to run next?

A.It selects the task with the highest priority
B.It selects the task with the smallest vruntime value ✅
C.It selects the task with the largest vruntime value
D.It selects the task in a round-robin fashion
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: CFS selects the task with the smallest vruntime value. This ensures that tasks that have received less CPU time (lower vruntime) are given priority, providing fairness. This is a key aspect of the CFS algorithm's goal of providing 'completely fair' scheduling.

Q14. For a task with a default priority (nice value 0), what is the relationship between vruntime and actual physical run time?

A.vruntime is always less than physical run time
B.vruntime is always greater than physical run time
C.vruntime is identical to physical run time ✅
D.vruntime is unrelated to physical run time
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: For tasks with normal priority (nice value 0), virtual run time is identical to actual physical run time. This means that if such a task runs for 200 milliseconds, its vruntime will also be 200 milliseconds. This provides a baseline for comparison with tasks of other priorities.

Q15. If a lower-priority task runs for 200 milliseconds, how will its vruntime compare to a normal priority task that also ran for 200 milliseconds?

A.Its vruntime will be lower
B.Its vruntime will be the same
C.Its vruntime will be higher ✅
D.The relationship cannot be determined
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: If a lower-priority task runs for 200 milliseconds, its vruntime will be higher than 200 milliseconds. This is because lower-priority tasks have higher rates of decay, meaning their vruntime increases faster than higher-priority tasks for the same amount of actual CPU time.

Q16. If a higher-priority task runs for 200 milliseconds, how will its vruntime compare to a normal priority task that also ran for 200 milliseconds?

A.Its vruntime will be lower ✅
B.Its vruntime will be the same
C.Its vruntime will be higher
D.The relationship cannot be determined
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: If a higher-priority task runs for 200 milliseconds, its vruntime will be less than 200 milliseconds. Higher-priority tasks have lower rates of decay, meaning their vruntime increases more slowly than lower-priority tasks for the same amount of actual CPU time.

Q17. What data structure does the CFS scheduler use to store runnable tasks?

A.A linked list
B.A red-black tree ✅
C.A hash table
D.A priority queue
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: CFS places each runnable task in a red-black tree, which is a balanced binary search tree. The key for this tree is based on the value of vruntime. This data structure allows efficient retrieval of the task with the smallest vruntime value.

Q18. In the CFS red-black tree, what does the leftmost node represent?

A.The task with the largest vruntime
B.The task with the smallest vruntime ✅
C.The task that has been running the longest
D.The task with the highest nice value
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In the CFS red-black tree, the leftmost node has the smallest key value. Since the key is based on vruntime, the leftmost node represents the task with the smallest vruntime, which means it has received the least CPU time and thus has the highest priority for being selected next.

Q19. How does the Linux scheduler optimize the selection of the next task from the red-black tree?

A.It caches the leftmost node in the variable rb_leftmost ✅
B.It searches the entire tree
C.It uses a separate array of pointers
D.It maintains a separate priority queue
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The Linux scheduler caches the leftmost node in the variable rb_leftmost. This optimization means that determining which task to run next requires only retrieving the cached value, rather than performing an O(lg N) tree traversal. This makes the selection process extremely efficient.

Q20. What is the time complexity of navigating to the leftmost node in a balanced red-black tree?

A.O(1)
B.O(lg N) ✅
C.O(N)
D.O(N lg N)
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Navigating a balanced red-black tree to discover the leftmost node requires O(lg N) operations, where N is the number of nodes in the tree. However, Linux optimizes this by caching the leftmost node, making the effective selection O(1).

Q21. What happens to a task in the CFS red-black tree when it becomes blocked (e.g., waiting for I/O)?

A.It is removed from the tree ✅
B.It remains in the tree with higher priority
C.It is moved to the right side of the tree
D.Its vruntime is reset
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When a task becomes not runnable (for example, if it is blocked while waiting for I/O), it is removed from the red-black tree. Only runnable tasks are stored in the tree. When the task becomes runnable again, it is reinserted into the tree.

Q22. In the CFS scheduler, how do I/O-bound tasks typically compare to CPU-bound tasks in terms of vruntime?

A.I/O-bound tasks have lower vruntime ✅
B.I/O-bound tasks have higher vruntime
C.Both have similar vruntime
D.vruntime is not applicable to I/O-bound tasks
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: I/O-bound tasks typically run for short periods and then block for I/O. As a result, they accumulate less actual CPU time than CPU-bound tasks. Therefore, their vruntime tends to be lower, giving them higher priority. This allows I/O-bound tasks to preempt CPU-bound tasks when they become ready.

Q23. In the CFS scheduler, what happens when an I/O-bound task becomes eligible to run while a CPU-bound task is executing?

A.The I/O-bound task waits until the CPU-bound task completes
B.The I/O-bound task preempts the CPU-bound task ✅
C.The scheduler switches to the next task in the queue
D.The I/O-bound task is added to the end of the ready queue
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: When an I/O-bound task becomes eligible to run (for example, when I/O it was waiting for becomes available), it typically has a lower vruntime than the CPU-bound task. Therefore, it will have higher priority and will preempt the CPU-bound task. This ensures good responsiveness for interactive and I/O-intensive workloads.

Q24. What real-time scheduling policies does Linux support based on the POSIX standard?

A.SCHED_OTHER and SCHED_BATCH
B.SCHED_FIFO and SCHED_RR ✅
C.SCHED_CFS and SCHED_RT
D.SCHED_NORMAL and SCHED_REAL
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Linux implements real-time scheduling using the POSIX standard, supporting SCHED_FIFO (first-in, first-out) and SCHED_RR (round-robin) real-time policies. These real-time policies run at a higher priority than normal (non-real-time) tasks.

Q25. What is the priority range for real-time tasks in Linux?

A.0 to 99 ✅
B.100 to 139
C.-20 to +19
D.0 to 139
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Real-time tasks in Linux are assigned static priorities within the range of 0 to 99. In this range, numerically lower values indicate higher relative priorities. These priorities are higher than those assigned to normal (non-real-time) tasks.

Q26. What is the priority range for normal (non-real-time) tasks in Linux?

A.0 to 99
B.100 to 139 ✅
C.-20 to +19
D.0 to 139
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Normal (non-real-time) tasks in Linux are assigned priorities from 100 to 139. This range is separate from the real-time priority range (0-99). Within this range, numerically lower values indicate higher relative priorities, with 100 being the highest normal priority.

Q27. How do nice values map to normal task priorities in Linux?

A.Nice value −20 maps to priority 100; nice value +19 maps to priority 139 ✅
B.Nice value +20 maps to priority 100; nice value −19 maps to priority 139
C.Nice value 0 maps to priority 100; nice value +19 maps to priority 139
D.Nice value −20 maps to priority 139; nice value +19 maps to priority 100
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: In Linux, nice values map to normal task priorities as follows: a nice value of −20 (the highest priority) maps to priority 100, and a nice value of +19 (the lowest priority) maps to priority 139. This provides a direct mapping between the nice value and the scheduler priority.

Q28. In the global Linux priority scheme, how do real-time task priorities compare to normal task priorities?

A.Real-time priorities (0-99) are higher than normal priorities (100-139) ✅
B.Normal priorities (100-139) are higher than real-time priorities (0-99)
C.Both have equal priority
D.The relationship depends on the scheduling class
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: In the global priority scheme, real-time tasks (priorities 0-99) run at a higher priority than normal tasks (priorities 100-139). This ensures that real-time tasks receive preferential treatment and can preempt normal tasks when needed.

Q29. What is the range of priorities for real-time tasks in Linux?

A.0 to 99 ✅
B.100 to 139
C.-20 to +19
D.1 to 40
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Real-time tasks in Linux are assigned static priorities within the range of 0 to 99. This range provides 100 distinct priority levels for real-time tasks, allowing fine-grained control over the priority of time-critical applications.

Q30. What is the relationship between nice values and task priorities in Linux?

A.Lower nice values = higher priorities ✅
B.Higher nice values = higher priorities
C.Nice values do not affect priorities
D.Nice values are only for real-time tasks
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: In Linux, numerically lower nice values indicate higher relative priorities. For example, a task with a nice value of −20 has the highest priority among normal tasks, while a task with a nice value of +19 has the lowest priority. This is why increasing the nice value is described as being 'nice' to other tasks.

Q31. What is the term 'nice' derived from in the context of Linux scheduling?

A.The idea that increasing the nice value makes a task 'nicer' to other tasks ✅
B.The idea that decreasing the nice value makes a task 'nicer'
C.The name of the developer who created the concept
D.The acronym for 'Non-Interactive Computing Environment'
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The term 'nice' comes from the idea that if a task increases its nice value (e.g., from 0 to +10), it is being 'nice' to other tasks in the system by lowering its relative priority. This allows other tasks to receive more CPU time.

Q32. What is the default scheduling policy for threads created in the POSIX real-time scheduling API example?

A.SCHED_OTHER
B.SCHED_FIFO ✅
C.SCHED_RR
D.SCHED_NORMAL
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In the POSIX real-time scheduling API example, the scheduling policy is set to SCHED_FIFO using the pthread_attr_setschedpolicy function. This demonstrates how to set real-time scheduling policies for threads in a POSIX-compliant system.

Q33. Which function is used in the POSIX real-time scheduling API to get the current scheduling policy?

A.pthread_attr_setschedpolicy
B.pthread_attr_getschedpolicy ✅
C.pthread_setschedpolicy
D.pthread_getschedpolicy
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The pthread_attr_getschedpolicy function is used to get the current scheduling policy from a thread attributes object. The example shows this function being used to retrieve and then print the current policy (SCHED_OTHER, SCHED_RR, or SCHED_FIFO).

Q34. In the CFS scheduler, what happens to targeted latency when the number of active tasks exceeds a certain threshold?

A.It remains the same
B.It increases ✅
C.It decreases
D.It is reset to zero
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Targeted latency can increase if the number of active tasks in the system grows beyond a certain threshold. This ensures that each task still gets a reasonable time slice even when many tasks are active, preventing any single task from being starved for too long.

Q35. What is the key difference between CFS and the O(1) scheduler regarding interactive process response?

A.CFS provides better response times for interactive processes ✅
B.O(1) provides better response times for interactive processes
C.Both provide the same response times
D.Neither supports interactive processes
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: CFS was designed to address the poor response times for interactive processes that were a drawback of the O(1) scheduler. CFS achieves this by using virtual run time and prioritizing tasks that have received less CPU time, which typically includes I/O-bound interactive tasks.

Q36. What does SCHED_FIFO stand for in Linux real-time scheduling?

A.First In, First Out ✅
B.Fair Input, Fair Output
C.Fast Interrupt, Fast Output
D.Fixed Interval, Fixed Order
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: SCHED_FIFO stands for First In, First Out, which is a real-time scheduling policy where a thread runs until it either completes or is blocked by a higher-priority thread. This is one of the POSIX real-time scheduling policies supported by Linux.

Q37. What does SCHED_RR stand for in Linux real-time scheduling?

A.Round Robin ✅
B.Real-time Response
C.Rate-based Round-robin
D.Recursive Round-robin
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: SCHED_RR stands for Round Robin, which is a real-time scheduling policy where threads of the same priority share CPU time in a round-robin fashion. This is the other POSIX real-time scheduling policy supported by Linux, alongside SCHED_FIFO.

Q38. In the global priority scheme of Linux, which has higher priority: a real-time task or a normal task?

A.A real-time task ✅
B.A normal task
C.Both have equal priority
D.It depends on the nice value
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: In the global priority scheme, real-time tasks have higher priority than normal tasks. Real-time tasks are assigned priorities in the range 0-99, while normal tasks are assigned priorities in the range 100-139. Since numerically lower values indicate higher priority, real-time tasks always preempt normal tasks.

Q39. What is the key feature of the CFS scheduler that allows it to be 'completely fair'?

A.It allocates CPU time based on virtual run time ✅
B.It uses a fixed time quantum for all tasks
C.It always gives equal priority to all tasks
D.It does not use preemption
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: CFS achieves fairness by using virtual run time (vruntime). Tasks that have received less CPU time have smaller vruntime values and are therefore given priority. This ensures that over time, all tasks receive a fair proportion of CPU time proportional to their nice values.

Q40. What is the minimum priority for a real-time task in Linux?

A.0 ✅
B.99
C.100
D.139
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: In Linux, real-time tasks are assigned priorities in the range of 0 to 99, where numerically lower values indicate higher relative priorities. Therefore, the minimum priority (lowest priority) for a real-time task is 99, and the highest priority is 0.

Q41. What is the maximum priority for a real-time task in Linux?

A.0 ✅
B.99
C.100
D.139
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: In Linux, real-time tasks are assigned priorities in the range of 0 to 99. Since numerically lower values indicate higher relative priorities, priority 0 represents the highest priority for a real-time task. This allows the most time-critical tasks to be assigned the highest priority.

Q42. What is the minimum priority for a normal task in Linux?

A.0
B.99
C.100
D.139 ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Normal tasks in Linux are assigned priorities in the range of 100 to 139, where numerically lower values indicate higher relative priorities. Therefore, the minimum priority (lowest priority) for a normal task is 139, and the highest priority is 100.

Q43. What is the maximum priority for a normal task in Linux?

A.0
B.99
C.100 ✅
D.139
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Normal tasks in Linux are assigned priorities in the range of 100 to 139. Since numerically lower values indicate higher relative priorities, priority 100 represents the highest priority for a normal task. This is the highest priority a non-real-time task can receive.

Q44. How does the CFS scheduler treat a task that has been given less processing time?

A.It is moved to the right side of the red-black tree
B.It is moved to the left side of the red-black tree ✅
C.It is given a lower priority
D.It is removed from the tree
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In the CFS red-black tree, tasks that have been given less processing time (smaller values of vruntime) are toward the left side of the tree. Since the leftmost node has the smallest vruntime, these tasks are given priority for execution, ensuring fairness.

Q45. How does the CFS scheduler treat a task that has been given more processing time?

A.It is moved to the left side of the red-black tree
B.It is moved to the right side of the red-black tree ✅
C.It is given a higher priority
D.It is preempted immediately
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In the CFS red-black tree, tasks that have been given more processing time (larger values of vruntime) are toward the right side of the tree. These tasks have lower priority for execution, allowing tasks with less CPU time to run first.

Q46. What is the purpose of the decay factor associated with vruntime in CFS?

A.To ensure lower-priority tasks receive less CPU time ✅
B.To ensure higher-priority tasks receive less CPU time
C.To ensure all tasks receive equal CPU time
D.To ensure tasks are scheduled in order of arrival
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The decay factor ensures that lower-priority tasks have higher rates of decay, meaning their vruntime increases faster than higher-priority tasks for the same amount of actual CPU time. This ensures that lower-priority tasks are effectively penalized, receiving less CPU time over the long term.

Q47. In the CFS scheduler, what is the relationship between a task's nice value and its vruntime decay rate?

A.Higher nice value = higher decay rate ✅
B.Higher nice value = lower decay rate
C.Nice value does not affect decay rate
D.Decay rate is fixed for all tasks
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Tasks with higher nice values (lower priority) have higher rates of decay. This means their vruntime increases faster for the same amount of actual CPU time, causing them to be scheduled less frequently. Conversely, tasks with lower nice values (higher priority) have lower decay rates.

Q48. What is the key advantage of using a red-black tree for task management in CFS?

A.It provides efficient insertion and retrieval operations ✅
B.It is the simplest data structure to implement
C.It requires no memory allocation
D.It is guaranteed to be perfectly balanced
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: A red-black tree is a balanced binary search tree that provides efficient insertion and retrieval operations (O(lg N)). This is important for the scheduler, which frequently adds and removes tasks from the run queue while needing to quickly find the task with the smallest vruntime.

Q49. What happens to a task's vruntime when it is preempted?

A.It is reset to zero
B.It is saved and later restored ✅
C.It continues to increase
D.It is decreased
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a task is preempted, its vruntime value is saved. When the task resumes execution, it continues from its saved vruntime value. This ensures that the task's accumulated CPU time is tracked correctly across preemptions, maintaining fairness in the scheduling algorithm.

Q50. What is the purpose of the POSIX real-time scheduling API example shown in Figure 6.20?

A.To demonstrate how to create threads with real-time scheduling policies ✅
B.To demonstrate how to create processes
C.To demonstrate how to allocate memory
D.To demonstrate how to handle signals
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The POSIX real-time scheduling API example demonstrates how to create threads with specific scheduling policies (SCHED_FIFO, SCHED_RR, or SCHED_OTHER). It shows the use of pthread_attr_setschedpolicy and pthread_attr_getschedpolicy to set and get scheduling policies for threads.

Q51. What scheduling policy is set in the POSIX real-time scheduling API example?

A.SCHED_OTHER
B.SCHED_FIFO ✅
C.SCHED_RR
D.SCHED_NORMAL
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In the example, the scheduling policy is set to SCHED_FIFO using the pthread_attr_setschedpolicy function. This demonstrates how to set a real-time FIFO scheduling policy for threads in a POSIX-compliant system.

Q52. What is the range of normal task priorities that corresponds to nice values?

A.Nice -20 to +19 maps to priorities 100 to 139 ✅
B.Nice -20 to +19 maps to priorities 0 to 99
C.Nice 0 to +19 maps to priorities 100 to 139
D.Nice -20 to 0 maps to priorities 100 to 139
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Normal tasks are assigned priorities from 100 to 139 based on their nice values. A nice value of −20 maps to priority 100 (highest priority), and a nice value of +19 maps to priority 139 (lowest priority). This provides a direct mapping between the nice value and the scheduler priority.

Q53. What does the variable rb_leftmost represent in the CFS scheduler?

A.The leftmost node of the red-black tree with the smallest vruntime ✅
B.The leftmost node of the red-black tree with the largest vruntime
C.The root node of the red-black tree
D.The rightmost node of the red-black tree
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The rb_leftmost variable caches the leftmost node of the red-black tree. In the CFS scheduler, the leftmost node has the smallest vruntime value, which represents the task with the highest priority for execution. Caching this value allows the scheduler to select the next task in O(1) time.

Q54. What happens to targeted latency when there are few active tasks in the system?

A.It remains at its default value ✅
B.It decreases
C.It increases
D.It is reset to zero
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When there are few active tasks, targeted latency remains at its default or minimum value. It only increases when the number of active tasks exceeds a certain threshold, ensuring that each task still gets a reasonable time slice even with many tasks.

Q55. What is the key insight behind the CFS scheduler's approach to fair scheduling?

A.It attempts to provide each task with a proportional share of CPU time ✅
B.It attempts to provide each task with equal CPU time
C.It attempts to prioritize I/O-bound tasks over CPU-bound tasks
D.It attempts to prioritize CPU-bound tasks over I/O-bound tasks
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The CFS scheduler aims to provide each task with a proportional share of CPU time based on its nice value. This is achieved through the vruntime mechanism, where tasks accumulate virtual run time at rates determined by their priority, ensuring that over time, each task receives its fair share of CPU time.

Q56. What is the significance of the CFS scheduler being 'completely fair'?

A.It provides equal CPU time to all tasks
B.It provides proportional CPU time based on nice values ✅
C.It guarantees that tasks never starve
D.It eliminates context switching overhead
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: CFS is 'completely fair' in the sense that it provides proportional CPU time to tasks based on their nice values. Tasks with higher priority (lower nice values) receive proportionally more CPU time than tasks with lower priority, but all tasks receive their fair share based on their allocated proportion.

Q57. What is the main reason the O(1) scheduler was replaced by CFS?

A.The O(1) scheduler had poor performance on SMP systems
B.The O(1) scheduler led to poor response times for interactive processes ✅
C.The O(1) scheduler did not support real-time processes
D.The O(1) scheduler consumed too much memory
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The O(1) scheduler was replaced because it led to poor response times for interactive processes common on desktop systems. The CFS scheduler was designed to provide better interactivity and fairness by using a more sophisticated vruntime-based approach.

Q58. How does the CFS scheduler ensure that a CPU-bound task does not starve I/O-bound tasks?

A.By giving I/O-bound tasks higher priority due to lower vruntime ✅
B.By giving CPU-bound tasks higher priority
C.By using a round-robin approach
D.By limiting the execution time of CPU-bound tasks
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: CFS ensures that I/O-bound tasks (which typically run for short periods and then block) receive higher priority because they accumulate less vruntime than CPU-bound tasks. This allows I/O-bound tasks to preempt CPU-bound tasks, ensuring good responsiveness for interactive and I/O-intensive workloads.

Q59. What is the range of priorities for all tasks in the Linux global priority scheme?

A.0 to 139 ✅
B.0 to 99
C.100 to 139
D.-20 to +19
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: In the Linux global priority scheme, real-time tasks are assigned priorities in the range 0-99, and normal tasks are assigned priorities in the range 100-139. Therefore, the complete range of priorities is 0 to 139, where numerically lower values indicate higher relative priorities.

Q60. What is the highest priority value in the Linux global priority scheme?

A.0 ✅
B.99
C.100
D.139
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: In the Linux global priority scheme, numerically lower values indicate higher relative priorities. Therefore, the highest priority value is 0, which is assigned to the highest-priority real-time tasks. This allows the most time-critical tasks to receive the highest priority.

Q61. What is the lowest priority value in the Linux global priority scheme?

A.0
B.99
C.100
D.139 ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: In the Linux global priority scheme, numerically lower values indicate higher relative priorities. Therefore, the lowest priority value is 139, which is assigned to the lowest-priority normal tasks (nice value +19). This ensures that even the lowest-priority tasks have a defined priority level.

Q62. What is the main difference between SCHED_FIFO and SCHED_RR in Linux real-time scheduling?

A.SCHED_FIFO allows preemption by higher-priority tasks; SCHED_RR allows time-sharing among same-priority tasks ✅
B.SCHED_FIFO uses round-robin; SCHED_RR uses FIFO
C.There is no difference
D.SCHED_FIFO is only for kernel threads
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The main difference is that SCHED_FIFO (First In, First Out) allows a thread to run until it completes or is blocked by a higher-priority thread, while SCHED_RR (Round Robin) allows threads of the same priority to share CPU time in a round-robin fashion, ensuring fairness among same-priority real-time tasks.

Q63. What is the purpose of the red-black tree in the CFS scheduler?

A.To store all tasks in the system
B.To store only runnable tasks and retrieve the one with the smallest vruntime ✅
C.To store tasks by priority
D.To store tasks by arrival time
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The red-black tree is used to store runnable tasks, with the key being the vruntime value. The tree is balanced, allowing efficient insertion and retrieval of tasks. The leftmost node of the tree has the smallest vruntime, which represents the task with the highest priority for execution.

Q64. What is the key insight behind the O(1) scheduler's design?

A.It runs in constant time regardless of the number of tasks ✅
B.It uses a round-robin approach
C.It assigns priorities based on nice values
D.It is optimized for SMP systems only
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The key insight behind the O(1) scheduler is that it runs in constant time (O(1)) regardless of the number of tasks in the system. This is achieved through the use of multiple run queues and bitmaps that allow the scheduler to quickly find the highest-priority task.

Q65. What was the primary goal of the CFS scheduler when it was introduced in Linux 2.6.23?

A.To improve performance on SMP systems
B.To provide better response times for interactive processes ✅
C.To support real-time scheduling
D.To reduce memory usage
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The primary goal of the CFS scheduler was to provide better response times for interactive processes, which was a known drawback of the O(1) scheduler. CFS achieves this by using a vruntime-based approach that gives priority to tasks that have received less CPU time, which typically includes interactive I/O-bound tasks.

Q66. How does the CFS scheduler handle a task with a nice value of +19?

A.It gives the task the lowest priority among normal tasks ✅
B.It gives the task the highest priority among normal tasks
C.It gives the task real-time priority
D.It ignores the nice value
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: A task with a nice value of +19 has the lowest priority among normal tasks. It maps to priority 139 in the global priority scheme, which is the lowest priority level for normal tasks. This task will receive the smallest proportion of CPU time among normal tasks.

Q67. How does the CFS scheduler handle a task with a nice value of −20?

A.It gives the task the highest priority among normal tasks ✅
B.It gives the task the lowest priority among normal tasks
C.It gives the task real-time priority
D.It ignores the nice value
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: A task with a nice value of −20 has the highest priority among normal tasks. It maps to priority 100 in the global priority scheme, which is the highest priority level for normal tasks. This task will receive the largest proportion of CPU time among normal tasks.

Q68. What is the purpose of the pthread_attr_init function in the POSIX real-time scheduling API example?

A.To initialize a thread attributes object with default values ✅
B.To create a new thread
C.To set the scheduling policy
D.To join a thread
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The pthread_attr_init function is used to initialize a thread attributes object with default values. This is the first step in the example, setting up the attributes object that will later be modified to set the scheduling policy and used to create threads.

Q69. What is the purpose of the pthread_create function in the POSIX real-time scheduling API example?

A.To create new threads with the specified attributes ✅
B.To initialize thread attributes
C.To set the scheduling policy
D.To join threads
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The pthread_create function is used to create new threads. In the example, it creates NUM_THREADS threads, each using the thread attributes object that has been configured with the SCHED_FIFO scheduling policy. The runner function is specified as the entry point for each thread.

Q70. What is the purpose of the pthread_join function in the POSIX real-time scheduling API example?

A.To wait for threads to complete ✅
B.To create new threads
C.To set the scheduling policy
D.To initialize thread attributes
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The pthread_join function is used to wait for threads to complete. In the example, it joins each of the created threads, blocking until each thread finishes execution. This ensures that the main thread waits for all worker threads to complete before exiting.

Q71. What does the runner function do in the POSIX real-time scheduling API example?

A.It performs some work and then exits ✅
B.It sets the scheduling policy
C.It creates threads
D.It joins threads
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The runner function is the entry point for each thread created in the example. It performs some work (indicated by the comment) and then calls pthread_exit to terminate the thread. This demonstrates the structure of a thread function in a POSIX program.

Q72. What is the key advantage of using scheduling classes in Linux?

A.It allows the kernel to use different scheduling algorithms based on system needs ✅
B.It simplifies the scheduler implementation
C.It reduces context switching overhead
D.It eliminates the need for priorities
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Scheduling classes allow the kernel to accommodate different scheduling algorithms based on the needs of the system and its processes. For example, the scheduling criteria for a Linux server may be different from those for a mobile device, and scheduling classes provide the flexibility to support these different requirements.

Q73. What is the relationship between a task's vruntime and its priority in the CFS scheduler?

A.Tasks with lower vruntime have higher priority ✅
B.Tasks with higher vruntime have higher priority
C.vruntime does not affect priority
D.vruntime is only used for real-time tasks
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: In the CFS scheduler, the task with the smallest vruntime value has the highest priority. This is because tasks with smaller vruntime have received less CPU time and are therefore given priority to ensure fairness. The scheduler selects the task with the smallest vruntime to run next.

Q74. What is the purpose of the pthread_attr_setschedpolicy function in the POSIX real-time scheduling API example?

A.To set the scheduling policy for threads created with the attributes object ✅
B.To get the current scheduling policy
C.To create a new thread
D.To join a thread
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The pthread_attr_setschedpolicy function is used to set the scheduling policy in a thread attributes object. In the example, it sets the policy to SCHED_FIFO, which will be used when threads are created with this attributes object. This demonstrates how to configure threads for real-time scheduling.

Q75. What is the primary reason for adding new scheduling classes to the Linux kernel?

A.To accommodate different scheduling algorithms based on system needs ✅
B.To simplify the existing scheduler
C.To reduce memory usage
D.To improve performance on single-core systems
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: New scheduling classes can be added to the Linux kernel to accommodate different scheduling algorithms based on the needs of the system and its processes. This flexibility allows Linux to adapt to various workloads and system types, from servers to mobile devices.

🔗 Related Topics (MCQs)