📝 Real time scheduling in The Linux System (12 MCQs)
Scheduling Tasks with Explicit Timing Requirements
Real-time scheduling in Linux supports tasks that need predictable access to processor time and must respond within defined timing constraints. Linux provides real-time scheduling policies such as SCHED_FIFO and SCHED_RR, along with the deadline-based SCHED_DEADLINE policy. These mechanisms support time-sensitive applications, although meeting a deadline depends on system configuration and workload behaviour.
Why Ordinary Fair Scheduling May Be Insufficient
Interactive and batch scheduling generally balances fairness and overall utilisation rather than guaranteeing a particular completion time. Industrial control, audio processing, robotics, and telecommunications may require bounded response. Real-time scheduling gives selected tasks stronger scheduling guarantees or prioritisation, but poorly controlled high-priority tasks can delay other system work.
FIFO, Round Robin and Deadline Scheduling
SCHED_FIFO runs the highest-priority eligible real-time task until it blocks, yields, or is pre-empted by a higher-priority task. SCHED_RR adds a time quantum among equal-priority tasks. SCHED_DEADLINE uses runtime, deadline, and period parameters with deadline-based admission and scheduling mechanisms.
Example of Periodic Audio Processing
An audio task must process a buffer every 10 milliseconds. It is configured with a suitable real-time scheduling policy and sufficient execution budget. If it receives processor time within the required interval, audio output remains continuous. Excessive execution or higher-priority interference may still cause missed processing deadlines.
Latency Control and Starvation Risks
Real-time policies reduce scheduling delays for important workloads, but they do not automatically guarantee hard real-time behaviour on every Linux configuration. Interrupt handling, memory faults, driver latency, locking, and resource contention affect predictability. Incorrect priorities can starve ordinary tasks, so admission control, resource limits, and priority design are essential.
Misconceptions About Linux Real Time Scheduling
'SCHED_FIFO gives every task an equal time slice' is false because FIFO tasks run until they yield, block, or are pre-empted. 'SCHED_RR never pre-empts tasks' ignores its time-slice rotation. 'Using a real-time policy guarantees every deadline' overlooks execution budgets and system latency.
Exam Focus: FIFO, Round Robin and Deadline Parameters
Compare SCHED_FIFO, SCHED_RR, and SCHED_DEADLINE by their scheduling behaviour. Explain priority pre-emption, equal-priority rotation, and runtime/deadline/period parameters. Scenario questions may ask which policy suits a periodic workload or identify why a real-time task can still miss its deadline.
Key Terms of Linux Real Time Scheduling
- SCHED_FIFO - Priority scheduling without time-slice rotation.
- SCHED_RR - Real-time round-robin policy.
- SCHED_DEADLINE - Deadline-based scheduling policy.
- Runtime - Execution budget allocated to a task.
- Deadline - Required completion time.
📝 All Real time scheduling in The Linux System MCQs
Q1. What does the CLONE_VM flag cause when passed to the clone() system call?
📖 Explanation: The CLONE_VM flag tells the kernel that the new task will share the parent's virtual memory area, meaning both tasks see the same address space. Option B describes this sharing correctly. Option A is wrong because it suggests a copy, which is what fork() does without CLONE_VM. Option C mixes file descriptor sharing, which is controlled by CLONE_FILES, not CLONE_VM. Option D refers to CLONE_SIGHAND. In a real‑time program, sharing memory allows fast data exchange between threads, which is why B is correct.
Q2. Why does Linux treat processes and threads as the same kind of entity called a task?
📖 Explanation: Linux represents a task as a collection of separate substructures such as the file‑system context, descriptor table, signal‑handler table, and memory descriptor. Because each component can be attached to a new task independently, the kernel can create a child that shares some parts and copies others, making the distinction between a process and a thread unnecessary. Option B states this mechanism, so it is correct. Option A is false because threads still have their own registers. Option C misstates kernel capability, and Option D is incorrect because threads may choose which resources to share.
Q3. A developer wants a thread that shares memory with its parent but keeps a private set of open files. Which combination of clone() flags should be used?
📖 Explanation: The developer wants memory sharing but private file descriptors. CLONE_VM makes the address space shared, while omitting CLONE_FILES keeps the descriptor tables separate. Therefore the correct flag set is only CLONE_VM, listed as option C. Option A adds CLONE_FILES, which would cause the file descriptors to be shared, violating the requirement. Option B adds CLONE_FS, which is unnecessary for this goal. Option D adds CLONE_SIGHAND, which would share signal handlers but does not affect the file‑descriptor requirement. Hence C is the appropriate choice.
Q4. How does sharing the virtual memory area (via CLONE_VM) influence priority inheritance mechanisms in real‑time scheduling?
📖 Explanation: When tasks share the same virtual memory via CLONE_VM, any priority change that a real‑time scheduler imposes on one task can be observed by the other because they operate on the same data structures. This enables faster propagation of priority inheritance, helping to avoid priority‑inversion problems. Option B captures this benefit. Option A incorrectly claims sharing prevents inheritance. Option C says there is no effect, which ignores the tight coupling of shared memory. Option D suggests forced equal priority, which is not true. Thus B is correct.
Q5. In a real‑time system, a task created with clone() shares signal handlers with its parent. What potential problem can arise if the parent later modifies a handler for a timer signal?
📖 Explanation: Because CLONE_SIGHAND makes the signal‑handler table common to both parent and child, a modification of the handler for a timer signal in the parent immediately affects the child as well. Both tasks may then execute the same handler when the timer expires, potentially causing duplicate actions such as double interrupts or resource updates. Option B describes this risk. Option A is wrong because the handler is shared, not isolated. Option C is false; the child will still receive the signal. Option D is extreme and not how the kernel behaves. Hence B is correct.
Q6. Which set of flags passed to clone() produces behavior identical to a standard fork() call?
📖 Explanation: To mimic the behavior of fork(), the new task must not share any of the parent’s resources. The clone() system call achieves this when it is invoked with no flags, because the kernel creates independent copies of the memory space, file‑system information, signal handlers, and file descriptors. Option A matches this description. Option B lists flags that cause sharing, which is the opposite of fork(). Options C and D each share at least one resource, so they do not replicate fork(). Therefore A is the right answer.
Q7. What is the effect of the CLONE_SIGHAND flag on inter‑task communication in a real‑time environment?
📖 Explanation: CLONE_SIGHAND causes the child to use the same signal‑handler table as its parent. In a real‑time environment this sharing lets multiple tasks respond to the same signal in a coordinated way, for example by using a common handler to adjust priorities or handle deadlines. Option C correctly states this coordinated response. Option A is wrong because sharing actually enables interaction, not isolation. Option B describes the opposite of what CLONE_SIGHAND does. Option D incorrectly says the child cannot handle signals at all. Thus C is the correct choice.
Q8. A system requires two concurrent activities: one I/O‑bound thread that must share file descriptors with the main task, and one CPU‑bound thread that must have a private memory space. Which two clone() calls correctly create these threads?
📖 Explanation: The I/O‑bound thread must share file descriptors, so the clone() call that creates it should include CLONE_FILES while not necessarily sharing memory; omitting CLONE_VM keeps its address space private. The CPU‑bound thread needs a private memory area and does not need shared descriptors, so it should be created without any flags. Option C matches this combination: first call with CLONE_FILES, second call with no flags. Option A swaps the flags, causing the wrong sharing. Option B shares both files and memory for the first thread, which is unnecessary. Option D reverses the intended behavior. Hence C is correct.
Q9. If a task created with clone() using CLONE_FS, CLONE_VM, CLONE_SIGHAND, and CLONE_FILES changes its current working directory, which of the following statements is true?
📖 Explanation: When CLONE_FS is used, the child and parent refer to the same file‑system context, meaning they see the same current working directory. Changing the directory in either task updates the shared context, so both observe the new directory. Option B correctly states that both parent and child see the change. Option A is false because the change is not private. Option C misinterprets CLONE_FS as preventing changes, which is incorrect. Option D invents an unsupported termination behavior. Therefore B is the appropriate answer.
Q10. Why does creating a thread with clone() and appropriate flags typically incur lower overhead than creating a separate process with fork() in a real‑time system?
📖 Explanation: clone() can reuse the existing task structure and only duplicate the components required by the flags, avoiding the costly copying of page tables, file descriptors, and other resources that fork() performs. This reduced overhead shortens the time needed to create a new thread, which is critical in real‑time systems where latency must be bounded. Option A describes this reuse accurately. Option B incorrectly claims fork() is faster. Option C misstates priority handling, and Option D is factually wrong because fork() does copy memory (using copy‑on‑write). Thus A is correct.
Q11. A bug appears where two threads unexpectedly close each other's file descriptors. Which clone() flag was most likely omitted when the threads were created?
📖 Explanation: The unexpected closing of file descriptors indicates that the two threads were operating on the same descriptor table. Sharing of file descriptors occurs only when the CLONE_FILES flag is set during clone(). If the flag had been omitted, each thread would have its own descriptor table, preventing the interference. Therefore the missing flag is CLONE_FILES, which is option B. Option A (CLONE_VM) concerns memory sharing, not descriptors. Option C (CLONE_SIGHAND) deals with signal handlers. Option D (CLONE_FS) relates to filesystem information. Hence B is the correct answer.
Q12. How does storing a process’s file‑system context, descriptor table, signal‑handler table, and virtual‑memory context in separate substructures enable Linux to treat threads and processes uniformly?
📖 Explanation: By keeping the file‑system context, descriptor table, signal‑handler table, and virtual‑memory descriptor in separate substructures, the kernel can decide for each new task which components to copy and which to share. This flexibility means a task can be created that shares some resources (behaving like a thread) or none (behaving like a process) without needing distinct system calls. Option B reflects this selective sharing mechanism. Option A incorrectly says all resources are forced to be shared. Option C denies any sharing, which contradicts Linux behavior. Option D merges everything, which is not how Linux is designed. Thus B is correct.