🎓 BookMCQ
← Back to 18. The Linux System

📝 Process scheduling in The Linux System (18 MCQs)

Scheduling Runnable Tasks on Linux Processors

Linux process scheduling selects which runnable task receives CPU time on an available processor. The scheduler manages competing tasks, balances workloads across cores, and applies policies for ordinary, real-time, and deadline-driven execution. Scheduling decisions consider task priority, scheduling class, processor availability, and fairness requirements rather than simply selecting processes in arrival order.

Why Runnable Tasks Need Controlled CPU Allocation

Multiple processes may be ready to execute while physical processors are limited. Without scheduling, one task could monopolise the CPU and delay interactive or critical work. Linux therefore uses scheduling classes and per-CPU run queues to manage runnable tasks, distribute processor time, and respond to changes in workload.

Scheduling Classes and Task Selection

Linux has scheduling classes for fair, real-time, deadline, and other specialised tasks. Each class defines selection behaviour and priority relative to other classes. The scheduler selects a runnable task from the appropriate run queue, performs a context switch when required, and may migrate tasks between CPUs for load balancing.

Example of Two CPU Bound Tasks

Two ordinary tasks, A and B, are continuously runnable on one CPU. The fair scheduling class distributes processor time according to scheduling weights and virtual execution progress. If A has a higher configured weight, it receives a larger share over time, while B still receives service according to the policy.

Fairness, Responsiveness and Kernel Version Changes

Scheduling balances throughput, interactive response, fairness, and workload priorities. Linux's fair scheduling implementation has evolved, so classic Completely Fair Scheduler explanations should be treated as a model of earlier and transitional implementations rather than an invariant description of every release. Real-time policies can pre-empt ordinary tasks and require careful administration.

Misconceptions About Linux Scheduling

'Linux always uses one scheduling algorithm for every task' ignores its scheduling classes. 'A higher nice value means higher CPU priority' reverses the usual nice-value relationship for ordinary tasks. 'Fair scheduling guarantees identical CPU time' ignores weights, runnable periods, and task execution requirements.

Exam Focus: Scheduling Classes, Priorities and Context Switches

Identify the purpose of fair, real-time, and deadline scheduling classes. Explain run queues, task selection, context switching, and CPU load balancing. Questions may test nice values and scheduling weights or compare ordinary scheduling with SCHED_FIFO, SCHED_RR, and SCHED_DEADLINE.

Key Terms of Linux Process Scheduling

  • Run queue - Collection of runnable tasks.
  • Scheduling class - Group defining task selection policy.
  • Nice value - Influences ordinary task scheduling weight.
  • Context switch - Changes the currently executing task.
  • Load balancing - Distributes runnable work among CPUs.
4
Easy
8
Medium
6
Hard

📝 All Process scheduling in The Linux System MCQs

Q1. Which system call creates a duplicate of a process in Linux?

A.fork() ✅
B.exec()
C.clone()
D.wait()
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: fork() creates an exact copy of the calling process, duplicating its address space, file descriptors, and execution context. exec() replaces the current process image, clone() can create a thread or process depending on flags, and wait() simply pauses a parent until a child terminates. Because the question asks for the call that duplicates a process without loading a new image, the correct answer is fork(). This aligns with the basic definition of process duplication in Linux.

Q2. Which clone() flag causes the child to share the parent’s virtual memory space?

A.CLONE_FS
B.CLONE_VM
C.CLONE_SIGHAND ✅
D.CLONE_FILES
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The flag that makes the child share the same address space as the parent is CLONE_VM. CLONE_FS shares filesystem information, CLONE_SIGHAND shares signal handlers, and CLONE_FILES shares the file‑descriptor table. By selecting CLONE_VM, both tasks operate on the same memory pages, enabling fast communication and shared data structures. Hence the correct answer is CLONE_VM, which directly provides shared virtual memory.

Q3. Why does Linux refer to both processes and threads as tasks?

A.Because Linux treats threads as separate processes for security.
B.To simplify the kernel’s scheduling algorithm.
C.Because tasks are the generic term for any flow of control, allowing the same data structures to represent both. ✅
D.To make debugging easier.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Linux uses the word task to describe any unit of execution, whether it originates from a traditional process or a lightweight thread. This abstraction lets the kernel use a single set of structures for scheduling, context switching, and resource management, avoiding the need for separate code paths. The other options describe unrelated motivations. Therefore, the correct answer is that tasks are a generic term for any flow of control, enabling uniform handling of processes and threads.

Q4. How does sharing the file‑descriptor table with the CLONE_FILES flag affect the behavior of parent and child?

A.The child gets its own copy of the file descriptors.
B.Both parent and child refer to the same descriptor entries, so closing a descriptor in one affects the other. ✅
C.The child cannot open new files.
D.The child inherits only read‑only copies of the descriptors.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When CLONE_FILES is specified, the parent and child point to the same file‑descriptor table. Any operation that modifies the table—such as closing, duplicating, or changing flags—affects both tasks because they reference the same underlying entries. The other options describe behaviors that occur when the table is not shared. Consequently, the correct answer is that both tasks share the same descriptor entries, making changes visible to each other.

Q5. What is the effect of invoking clone() with no flags compared to using fork()?

A.The child shares all resources automatically.
B.The child runs in the same address space but with separate file tables.
C.The child behaves like a thread created by clone().
D.The child behaves like a process created by fork(), with no shared resources unless flags are specified. ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: If clone() is called without any flags, it does not share any of the parent’s resources, reproducing the behavior of fork(): the child receives its own copies of memory, file‑descriptor table, signal handlers, and filesystem context. The other options describe partial sharing or thread‑like behavior, which only occurs when appropriate flags are set. Therefore, the correct answer is that the child behaves like a process created by fork(), with no shared resources by default.

Q6. How does storing a process’s context in separate substructures (e.g., file‑system context, virtual memory) enable resource sharing?

A.Separate substructures allow the kernel to copy only the needed parts when a new task is created, enabling selective sharing. ✅
B.It forces all resources to be duplicated, preventing any sharing.
C.It stores the entire process state in a single large structure, making sharing impossible.
D.It eliminates the need for any system calls.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Linux keeps each aspect of a process—such as its filesystem context, memory map, and signal table—in distinct data structures. When a new task is created, the kernel can choose to point to the existing structures instead of copying them, which is exactly what the CLONE_* flags control. This selective sharing reduces overhead and enables threads to share resources efficiently. The other statements contradict the design goal of modular context storage. Hence, the correct answer is that separate substructures allow selective sharing.

Q7. In scheduling, why might a thread created with clone() that shares memory be preferred over a separate process?

A.Threads have higher priority by default.
B.Separate processes can never share memory.
C.Shared memory reduces context‑switch overhead and improves cache locality, making scheduling more efficient. ✅
D.Processes are always scheduled on different CPUs.
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: When two tasks share the same memory region, the processor can keep relevant pages in cache between context switches, reducing the amount of memory traffic required to reload data. This improves overall system throughput and makes the scheduler’s job easier because the tasks behave more like a single execution unit. The other options are either false or unrelated to scheduling efficiency. Therefore, the correct answer is that shared memory reduces overhead and improves cache locality.

Q8. A program needs to spawn a worker that shares the same open file descriptors but not signal handlers. Which combination of flags should be used?

A.CLONE_FS | CLONE_SIGHAND
B.CLONE_VM | CLONE_FILES
C.CLONE_FS | CLONE_VM | CLONE_FILES
D.CLONE_FS | CLONE_VM | CLONE_FILES ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: To share open file descriptors, the CLONE_FILES flag is required. To avoid sharing signal handlers, CLONE_SIGHAND must be omitted. The worker does not need to share the filesystem context or memory space for this specific requirement, so the minimal set that satisfies the condition is CLONE_FS, CLONE_VM, and CLONE_FILES, which together give the desired sharing without signal‑handler sharing. Thus the correct answer is the option that includes CLONE_FILES but excludes CLONE_SIGHAND.

Q9. If a parent process changes its current working directory after creating a child with clone() using CLONE_FS, what happens to the child's cwd?

A.The child sees the new directory because the filesystem information is shared. ✅
B.The child remains in the original directory because its cwd was copied at creation.
C.The child crashes.
D.The child gets a permission error.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The CLONE_FS flag tells the kernel to share the filesystem context, which includes the current working directory. Consequently, any change made by the parent to the cwd is immediately visible to the child, because both tasks reference the same structure. If the flag were not set, each would have its own copy, resulting in the second option. Since the flag is present, the correct answer is that the child sees the new directory.

Q10. Suppose two threads created with clone() share CLONE_VM and CLONE_FILES, but one thread crashes due to a segmentation fault. What is likely effect on the other thread?

A.The other thread continues unaffected because they have separate stacks.
B.The other thread is likely to be terminated as well because they share the same address space and file table. ✅
C.Only the crashing thread is affected; the other continues normally.
D.Both threads become zombies.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: When CLONE_VM is used, both threads operate in the same virtual memory space, meaning a fault that corrupts shared memory can affect all participants. Additionally, CLONE_FILES means they share the same file‑descriptor table, so a fatal error in one thread often leads the kernel to terminate the entire task group. Therefore, the most probable outcome is that the second thread is also terminated, making option B correct.

Q11. An OS designer wants to implement a scheduler that gives higher priority to tasks that share memory with the current task. Which property of clone() flags supports this design?

A.CLONE_SIGHAND
B.CLONE_FS
C.CLONE_VM ✅
D.CLONE_FILES
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The CLONE_VM flag explicitly indicates that the child shares the parent’s virtual memory space. A scheduler that prefers tasks with shared memory can check for this flag to boost priority, because shared memory reduces context‑switch costs and improves cache usage. The other flags relate to filesystem information, signal handlers, or file descriptors, which are not directly tied to memory sharing. Hence, CLONE_VM is the flag that supports the described scheduling policy.

Q12. A developer wants to create a thread that does not inherit the parent's open files but needs the same memory space. Which flag set should be used?

A.CLONE_SIGHAND | CLONE_FILES
B.CLONE_VM ✅
C.CLONE_FS | CLONE_SIGHAND
D.CLONE_FS | CLONE_FILES
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: To share the same address space, the CLONE_VM flag must be set. Since the developer does not want the open file descriptors to be shared, CLONE_FILES must be omitted. No other flags are required for this specific goal. Therefore, the correct answer is simply CLONE_VM, which provides shared memory while keeping file descriptors separate.

Q13. In a multi‑threaded server, using clone() with CLONE_SIGHAND leads to what consequence when one thread installs a new signal handler?

A.The new handler is visible only to the thread that set it.
B.The handler is ignored by all threads.
C.The handler causes a segmentation fault.
D.The new handler becomes effective for all threads sharing CLONE_SIGHAND, potentially altering behavior of the entire task. ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: CLONE_SIGHAND makes the signal‑handler table shared among all tasks that were created with this flag. Consequently, when any one thread registers or changes a handler, the modification is visible to every other thread that shares the same table. This can affect the entire task’s response to signals. The other options describe behaviors that occur when the handler table is not shared. Thus, the correct answer is that the new handler becomes effective for all threads sharing CLONE_SIGHAND.

Q14. If a program uses fork() instead of clone() with CLONE_VM, what is the impact on inter‑thread communication speed?

A.fork() creates separate memory spaces, so communication requires inter‑process mechanisms, making it slower than clone() with shared memory. ✅
B.fork() is faster because it does not share memory.
C.clone() with CLONE_VM is slower due to extra synchronization.
D.Both have identical speed.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: fork() creates a completely separate address space for the child, so any data exchange must go through pipes, sockets, or shared memory segments set up explicitly, which adds overhead. In contrast, clone() with CLONE_VM places parent and child in the same memory region, allowing direct reads and writes without extra system calls, thus speeding up communication. The other statements misrepresent the performance characteristics. Therefore, the correct answer is that fork() leads to slower inter‑thread communication compared to clone() with shared memory.

Q15. A developer writes code using clone() with only CLONE_FS flag. After creating the child, both parent and child modify a global variable. What will be observed?

A.Both processes see independent values because memory is not shared. ✅
B.The child cannot modify the variable.
C.Both processes see the same updated value because they share the same memory region.
D.The program crashes.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: CLONE_FS only shares filesystem information; it does not affect the virtual memory layout. Since the memory space is not shared, each task has its own copy of the global variable. However, because the flag list includes only CLONE_FS, the child actually receives a separate memory region, so modifications are independent. The correct observation is that both see the same updated value only when memory is shared, which is not the case here. Therefore, the correct answer is that both processes see independent values, which corresponds to option A. (Correct answer: A)

Q16. Given a set of tasks with various clone flag configurations, which task will have the smallest memory footprint?

A.Task created with CLONE_VM | CLONE_FILES | CLONE_SIGHAND | CLONE_FS ✅
B.Task created with no flags (behaves like fork())
C.Task created with only CLONE_FS
D.Task created with only CLONE_SIGHAND
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: When all four CLONE_* flags are used, the new task shares the parent’s memory, file descriptors, signal handlers, and filesystem context, meaning the kernel does not need to allocate separate copies of these resources. This results in the smallest additional memory consumption compared to tasks that duplicate any of these structures. The task with no flags must copy the entire memory space, leading to the largest footprint. Hence, the task created with all four flags has the smallest memory footprint.

Q17. Why might a developer choose clone() with all four flags over creating separate processes with fork() for a thread pool?

A.clone() with all flags requires more system calls.
B.fork() provides better isolation.
C.Using fork() avoids shared memory issues.
D.clone() with all four flags creates lightweight threads that share resources, reducing overhead compared to separate processes. ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Selecting all four CLONE_* flags causes the new task to share the parent’s memory, file descriptors, signal handlers, and filesystem context, effectively creating a lightweight thread. This shared‑resource model reduces the amount of duplicated kernel data, lowers context‑switch costs, and improves cache performance, all of which are advantageous for a thread pool that needs many concurrent workers. fork() creates fully independent processes, incurring higher overhead. Therefore, the correct answer is that clone() with all four flags creates lightweight threads with reduced overhead.

Q18. Consider a scenario where a parent process creates a child with clone() sharing CLONE_VM and CLONE_FILES, then closes a file descriptor in the parent. What happens to the child's ability to use that descriptor?

A.The child loses access to that descriptor because the underlying file table entry is removed. ✅
B.The child retains the descriptor because it was already opened.
C.The child receives a duplicate descriptor automatically.
D.The child’s descriptor becomes read‑only.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Because CLONE_FILES makes the file‑descriptor table shared, any operation that modifies the table—such as closing a descriptor—affects both the parent and the child. When the parent closes the descriptor, the shared entry is removed, and the child can no longer use that descriptor. The other options describe behaviors that would occur only if the descriptor tables were separate. Therefore, the correct answer is that the child loses access to the descriptor.

🔗 Related Topics (MCQs)