📝 Symmetric multiprocessing in The Linux System (8 MCQs)
Linux Execution Across Multiple Processor Cores
Symmetric multiprocessing, or SMP, allows multiple processors or cores to execute kernel and user tasks concurrently while sharing main memory and operating system resources. Linux supports SMP through per-CPU scheduling structures, synchronisation primitives, interrupt management, and load balancing. Each processor can run tasks independently, while the kernel coordinates access to shared data and system-wide resources.
Why Single Processor Execution Limits Throughput
A single processor can execute only one task at a time, creating a limit for workloads with independent operations. SMP increases potential parallel execution and system throughput. However, adding processors creates competition for shared memory, caches, locks, and I/O resources, so coordination becomes necessary to preserve correctness.
Per CPU Run Queues and Load Balancing
Linux maintains CPU-specific scheduling information and selects runnable tasks for each available processor. The scheduler can migrate tasks between CPUs to balance workloads, subject to affinity and topology considerations. Locks and atomic operations protect shared kernel structures, while interrupt routing allows hardware events to be handled by suitable processors.
Example of Parallel Execution on Four Cores
A Linux server has four processor cores and four independent CPU-bound tasks. The scheduler places runnable tasks on available CPUs so all four can execute concurrently. If one task blocks for I/O, another runnable task may use that core, improving overall processor utilisation.
Scalability, Cache Effects and Synchronisation Costs
SMP can increase throughput and reduce execution time for parallel workloads. Performance gains depend on task independence, memory bandwidth, cache locality, and lock contention. Shared data may cause cache coherence traffic, while poorly balanced workloads leave some processors idle. CPU affinity and NUMA-aware placement can improve locality on larger systems.
Misconceptions About Symmetric Multiprocessing
'Every CPU runs a separate independent kernel' is false because processors cooperate within one kernel instance. 'Four cores guarantee four times the performance' ignores serial work and contention. 'Any task may migrate without consequence' overlooks cache locality, affinity, and NUMA memory placement.
Exam Focus: SMP Scheduling and Shared Memory
Explain how Linux schedules tasks across multiple CPUs and why shared data needs synchronisation. Distinguish task migration from parallel execution. Questions may examine per-CPU run queues, load balancing, processor affinity, cache coherence, and why additional cores do not always produce proportional speedup.
Key Terms of Linux SMP
- SMP - Multiple processors sharing system memory.
- CPU affinity - Preferred or permitted processor assignment.
- Load balancing - Distributing tasks among CPUs.
- Cache coherence - Maintaining consistent cached data.
- NUMA - Non-uniform memory access architecture.
📝 All Symmetric multiprocessing in The Linux System MCQs
Q1. Which system call creates a new task that shares the same memory space when the CLONE_VM flag is used?
📖 Explanation: The clone() system call creates a new task, and when the CLONE_VM flag is supplied the child shares the parent’s virtual memory area. Fork() always creates a separate memory space, exec() replaces the current process image, and wait() does not create new tasks. Because the memory is shared, both tasks see the same variables, which is essential for thread‑like behavior. This directly matches the definition of clone() with CLONE_VM.
Q2. Why can Linux treat processes and threads without a formal distinction?
📖 Explanation: Linux separates a task’s context into independent structures such as the file‑system context, descriptor table, signal‑handler table, and virtual‑memory context. The main task structure only holds references to these substructures, so a task can share any of them with another task. This design lets a thread and a process appear the same to the kernel, unlike systems that keep a single monolithic process record.
Q3. How does sharing the file‑descriptor table (CLONE_FILES) affect communication between a parent and its child task?
📖 Explanation: When CLONE_FILES is set, the parent and child use the same open‑file table, meaning any read/write operation updates the shared file offset. Consequently, data written by one task is immediately visible to the other, facilitating coordinated I/O. The other options describe effects of different flags: isolation occurs without CLONE_FILES, signal handling relates to CLONE_SIGHAND, and memory sharing concerns CLONE_VM.
Q4. A developer wants a thread that shares memory and open files but keeps its own signal handlers. Which flag combination should be used?
📖 Explanation: CLONE_VM shares the virtual memory area, and CLONE_FILES shares the open‑file table, giving the child the same memory and file descriptors as the parent. By omitting CLONE_SIGHAND, each task keeps its own signal‑handler table, satisfying the requirement. CLONE_FS would share the current working directory, which isn’t needed, and CLONE_SIGHAND would force shared handlers, contrary to the goal.
Q5. A parent process opens a log file, then calls clone() with CLONE_FILES. The child writes a message, and the parent reads from the file descriptor afterward. What is the most likely outcome?
📖 Explanation: With CLONE_FILES, the parent and child share the same open‑file table, including the file offset. When the child writes, the offset advances, so a subsequent read by the parent starts from the new position and can retrieve the written data. If the offsets were independent, the parent would not see the write, but sharing causes the observed behavior.
Q6. A programmer uses clone() without any flags to run parallel tasks, then modifies a global counter in the child expecting isolation. What problem is most likely to occur?
📖 Explanation: When no flags are supplied, clone() behaves like fork(): the child receives a copy‑on‑write view of the parent’s memory. However, any write to a global variable forces a private copy, so the child’s update does not affect the parent, leading to inconsistent results if the programmer assumes isolation. The real issue is that memory is not truly shared, producing race‑like behavior rather than isolation.
Q7. What does the CLONE_FS flag cause the child task to share with its parent?
📖 Explanation: CLONE_FS explicitly shares the filesystem context, meaning both tasks see the same current working directory, root directory, and mount points. This allows them to operate on the same pathnames without changing each other’s view. The other options correspond to different flags: CLONE_VM shares memory, CLONE_SIGHAND shares signal handlers, and CLONE_FILES shares open files.
Q8. A server creates a new task for each client connection using clone() with only CLONE_FILES. After many connections, memory usage spikes. Which flag should be added to reduce memory consumption?
📖 Explanation: Using only CLONE_FILES means each new task gets its own virtual memory area, so the memory footprint grows with every connection. Adding CLONE_VM makes all tasks share the same memory space, dramatically lowering per‑task memory usage. The other flags affect filesystem context, signal handling, or file descriptor sharing, which do not directly impact memory consumption.