🎓 BookMCQ
← Back to 18. The Linux System

📝 Virtual memory in The Linux System (40 MCQs)

Virtual Address Spaces for Linux Processes

Linux virtual memory gives each process an address space that is separate from the physical arrangement of RAM. The memory management subsystem translates virtual addresses into physical page frames through page tables and processor memory management hardware. Virtual memory supports process isolation, demand paging, shared mappings, memory-mapped files, and controlled use of swap space.

Why Processes Need Independent Address Spaces

Without virtual memory, processes would require careful manual coordination of physical addresses and could accidentally overwrite one another's data. Separate address spaces allow applications to use convenient logical ranges while the kernel controls physical placement. This abstraction also enables memory sharing, protection, and execution of programs whose combined memory demand exceeds available RAM.

Page Tables, Demand Paging and Page Faults

The processor translates virtual addresses through page tables, commonly aided by a translation lookaside buffer. If a required page is not resident or access violates permissions, a page fault transfers control to the kernel. The kernel may load file data, allocate a zero-filled page, copy a shared page, or reject an invalid access.

Example of a Demand Paged File Mapping

A process maps a 12 KB file region using 4 KB pages. Initially, the pages may not occupy physical memory. When the process accesses the second page, a page fault can cause Linux to retrieve the corresponding file data into RAM and update the process's page tables.

Isolation, Memory Pressure and Swap Activity

Virtual memory enables large address spaces, sharing, and protection between processes. Page faults and swapping add latency, particularly when memory pressure is high. The kernel reclaims suitable pages and may write anonymous memory to swap. Excessive paging can cause thrashing, while incorrect mappings or permission checks can threaten isolation.

Misconceptions About Linux Virtual Memory

'A virtual address is a physical RAM address' ignores address translation. 'Every page fault indicates a programming error' is false because valid demand paging causes faults. 'Swap makes RAM unnecessary' overlooks the much higher latency of secondary storage and the performance cost of paging.

Exam Focus: Address Translation and Page Fault Handling

Trace virtual-to-physical translation using page tables and a TLB. Explain the stages of a valid demand page fault and distinguish it from an invalid memory access. Questions may examine page size, page offsets, file mappings, copy-on-write, and the performance consequences of swapping.

Key Terms of Linux Virtual Memory

  • Virtual address - Address used by a process.
  • Page table - Maps virtual pages to physical frames.
  • Page fault - Exception requiring memory fault handling.
  • TLB - Cache of address translations.
  • Swap - Disk space used for displaced memory pages.
9
Easy
20
Medium
11
Hard

📝 All Virtual memory in The Linux System MCQs

Q1. A program calls clone() with only the CLONE_VM flag. Which resource is shared between the parent and child?

A.The memory address space ✅
B.The file‑system information
C.The set of open files
D.No resources are shared
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The CLONE_VM flag tells the kernel to use the same virtual‑memory mappings for both tasks, so they read and write to the same pages. Consequently, changes made by one are visible to the other. File‑system info, open‑file tables, and signal handlers are not affected because those require their own flags. This sharing reduces the overhead of copying page tables, which is why the memory space is the only resource shared in this scenario.

Q2. Why does storing a process’s virtual‑memory context in a separate substructure allow Linux to treat threads and processes similarly?

A.Because the CPU registers are duplicated for each thread
B.Because each thread gets its own page table
C.Because the memory context can be shared or isolated independently of other resources ✅
D.Because Linux copies the entire process image for every thread
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Linux keeps the virtual‑memory descriptor (e.g., page tables) in its own data structure separate from other parts like file descriptors or signal tables. When a thread is created, the kernel can point the new task to the same memory descriptor, sharing it, or allocate a new one for isolation. This modular design lets the same clone() system call create either a fully independent process (no sharing) or a lightweight thread (shared memory) simply by choosing which substructures to share.

Q3. Which clone() flag makes the set of open files shared between the parent and child?

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

📖 Explanation: The flag that controls sharing of the file‑descriptor table is CLONE_FILES. When this flag is present, both tasks refer to the same table, so a file opened by one is immediately visible to the other. CLONE_FS shares the current working directory, CLONE_SIGHAND shares signal handlers, and CLONE_VM shares the memory space. Knowing the exact purpose of each flag is essential for correctly configuring process‑level resource sharing.

Q4. A developer wants two tasks to have separate address spaces but to share their open file descriptors. Which combination of clone() flags should be used?

A.CLONE_VM | CLONE_FILES
B.CLONE_FILES only ✅
C.CLONE_VM only
D.No flags (equivalent to fork())
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: To keep address spaces separate, the CLONE_VM flag must be omitted, because that flag causes the memory mappings to be shared. The only resource that needs to be shared is the file‑descriptor table, which is achieved with the CLONE_FILES flag alone. Using both flags would cause memory to be shared, while using no flags would duplicate both memory and file tables, which is not the desired outcome.

Q5. Compare fork() with clone() called without any flags. Which statement best describes their differences in resource sharing and performance?

A.Both share all resources, but clone() is faster
B.fork() shares memory, clone() does not
C.fork() creates a completely independent copy, while clone() without flags still creates an independent copy but incurs extra overhead for handling separate subcontexts ✅
D.clone() without flags behaves exactly like fork() with no performance difference
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: When clone() is invoked with no flags, it behaves like fork(): the child receives its own copies of the virtual‑memory, file‑system, signal, and file‑descriptor contexts. However, the kernel still has to set up separate substructures for the new task, which adds a small amount of bookkeeping overhead compared with a plain fork(). The key distinction is that no resources are shared, so the two tasks are independent, but the implementation cost is slightly higher.

Q6. A server uses clone() with CLONE_VM and CLONE_SIGHAND to create a worker task that handles client requests. If a signal handler modifies a global variable, what problem is most likely to arise?

A.The modification will be isolated to the worker, preventing interference
B.Both parent and worker may concurrently modify the variable, causing a race condition ✅
C.The signal handler will be ignored in the parent process
D.The worker will receive a separate copy of the variable, leading to inconsistency
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Because CLONE_VM shares the entire address space and CLONE_SIGHAND shares the signal‑handler table, the parent and worker execute the same handler code on the same memory. If the handler writes to a global variable, both tasks can access and modify it at the same time, producing a classic race condition unless additional synchronization (e.g., mutexes) is used. The other options describe behaviors that occur only when the memory or signal tables are not shared.

Q7. Why does Linux not distinguish between a process and a thread at the API level?

A.Because threads are implemented as separate processes with identical IDs
B.Because the kernel only tracks tasks, and resource sharing is controlled by flags ✅
C.Because Linux lacks support for true threads
D.Because processes cannot share memory in Linux
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Linux’s kernel uses a single structure called a task to represent any unit of execution. Whether that task behaves like an independent process or a thread depends entirely on which resources are shared, as specified by the flags passed to clone(). This design eliminates a separate “thread” object and makes the distinction purely a matter of shared state, simplifying the scheduler and allowing flexible creation of both processes and threads using the same system call.

Q8. On a system with limited virtual memory, using clone() with CLONE_VM to create a new task will most likely result in which effect on overall memory usage?

A.Memory usage doubles because each task gets its own address space
B.Memory usage stays roughly the same because the address space is shared ✅
C.Memory usage slightly increases due to separate kernel stacks
D.Memory usage becomes unpredictable and often exceeds physical RAM
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When CLONE_VM is set, the child task shares the parent’s page tables, so both refer to the same physical pages. The only additional memory consumption comes from the new task’s kernel stack and minimal bookkeeping structures, which are relatively small. Therefore, total virtual‑memory consumption does not grow proportionally with the number of tasks, making option B the correct description of the expected behavior.

Q9. A program calls clone with the flags CLONE_FS, CLONE_VM, CLONE_SIGHAND, and CLONE_FILES. Which option correctly lists all flags required to make the child share the same memory space, file‑system information, signal handlers, and open files?

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

📖 Explanation: Option D lists every flag that directs clone to share the four resource categories. CLONE_VM shares the virtual memory, CLONE_FS shares the filesystem context, CLONE_SIGHAND shares signal handlers, and CLONE_FILES shares the open‑file table. The other options omit one or more required flags, so the child would not share all resources. This matches the behavior described for creating a thread‑like task in Linux.

Q10. Why can Linux treat threads and processes without a distinct type distinction?

A.Because both use the same scheduling algorithm
B.Because Linux stores each resource in separate substructures ✅
C.Because threads are always created with fork
D.Because processes cannot have their own memory
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Linux separates a task’s file‑system context, descriptor table, signal‑handler table, and virtual‑memory context into independent data structures. When a new task is created, the kernel can choose which of those structures to share, giving the appearance of a thread or a process. Option B captures this design; the other choices describe unrelated mechanisms or false statements, so they do not explain the lack of a separate thread type.

Q11. A developer wants two tasks created with clone to share the same set of open file descriptors but to have independent virtual memory spaces. Which combination of flags should be used?

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

📖 Explanation: CLONE_FILES causes the child to share the open‑file table while leaving the virtual memory unshared, which satisfies the requirement for independent address spaces. Option A provides exactly that flag set. Option B would share memory but not files, Option C shares unrelated resources, and Option D would also share memory, violating the independence condition.

Q12. When clone is invoked with CLONE_VM, how does the virtual memory region appear to the parent and child?

A.Each gets a copy‑on‑write private mapping
B.Child gets a completely separate address space
C.Both see the same pages and modifications are visible to both ✅
D.Memory is unshared until exec
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: CLONE_VM tells the kernel to let the parent and child use the same address space; any page written by either task is seen by the other because the mapping is truly shared, not merely copy‑on‑write. Option C states this shared visibility. Option A describes copy‑on‑write behavior, which occurs only when CLONE_VM is omitted. Options B and D are inaccurate descriptions of the effect of CLONE_VM.

Q13. Which system call in Linux creates a new task that can optionally share resources with its parent?

A.fork
B.execve
C.clone ✅
D.waitpid
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The clone system call allows the caller to specify flags that determine which resources—such as memory, files, or signal handlers—are shared with the newly created task. This flexibility makes clone the only call that can create a thread‑like task. fork always creates a separate copy of resources, execve replaces the current image, and waitpid merely waits for termination, so they do not meet the definition.

Q14. Process P calls clone with CLONE_VM to create task T, then T calls execve to run a new program. What happens to the shared memory region after execve?

A.It remains shared between P and T
B.It is replaced by the new program's memory ✅
C.It becomes read‑only
D.It is duplicated for T only
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When T invokes execve, the kernel discards the existing memory mappings and builds a fresh address space for the new program image. Because CLONE_VM only affects the memory layout before exec, the shared region is lost and replaced by the executable’s own mappings. Option B reflects this replacement. Options A, C, and D describe behaviors that do not occur after execve, which creates a brand‑new memory layout.

Q15. How does Linux’s lack of a separate process vs. thread classification affect its scheduler’s view of tasks?

A.Scheduler gives higher priority to threads
B.Scheduler treats all tasks uniformly regardless of shared resources ✅
C.Scheduler uses separate queues for threads
D.Scheduler cannot schedule threads
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Linux’s scheduler sees every runnable entity as a task and makes scheduling decisions based solely on attributes like priority and state, not on whether the task shares resources with another. Consequently, threads and processes are scheduled in the same way, which is captured by option B. The other options suggest special treatment or limitations that do not exist in the Linux scheduler design.

Q16. Two tasks created with clone share a memory region, but one task now needs a private copy of that region. Which system call should it use to detach the shared region?

A.unshare ✅
B.fork
C.execve
D.mmap
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The unshare system call lets a running task drop shared resources such as a memory mapping, causing subsequent modifications to affect only the calling task. By unsharing the memory region, the task obtains a private copy while the other task continues to use the original shared mapping. Option A correctly identifies this call. Fork creates a new task, execve replaces the image, and mmap creates new mappings but does not detach an existing shared region.]

Q17. What defines the lifetime of a virtual address space in a Linux process?

A.The period from process creation until the process terminates ✅
B.The interval between a fork() and an exec() call
C.The time a file descriptor remains open
D.The duration the kernel stays loaded in memory
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The virtual address space exists as long as the process exists. When the kernel creates a process, it allocates an address space that persists until the process calls exit() or is killed. Options B, C, and D describe unrelated lifetimes: fork‑exec intervals, file descriptor usage, and kernel residency, none of which determine the address space duration. Therefore the correct choice is A.

Q18. How does using clone() with the CLONE_VM flag affect the relationship between the parent and child address spaces?

A.Each gets a separate copy‑on‑write address space
B.Both share the same physical memory pages ✅
C.The child receives no address space at all
D.The parent loses its address space
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: CLONE_VM tells the kernel to let the parent and child share the same virtual memory area. They operate on the same page tables, so changes by one are visible to the other unless copy‑on‑write occurs. Option A describes the default fork behavior, not CLONE_VM. Option C is false because a child always has an address space. Option D is incorrect; the parent retains its space. Hence B is correct.

Q19. A process creates three threads via clone() with CLONE_VM. One thread calls exit() while the other two continue running. What happens to the virtual address space?

A.It is released as soon as the first thread exits
B.It remains until the entire process terminates ✅
C.It is freed after each thread exits
D.It is unaffected until the parent process calls exec()
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In Linux, threads created with CLONE_VM share a single virtual address space. The address space persists as long as any thread belonging to the process is alive. Exiting one thread does not free the memory; only when the last thread (or the main task) exits does the kernel release the address space. Options A and C incorrectly imply early deallocation, and D ties deallocation to exec, which is unrelated. Thus B is correct.

Q20. Why can the lifetime of a virtual address space cause memory fragmentation in long‑running Linux processes?

A.Because the kernel never reuses freed pages ✅
B.Because address spaces grow monotonically without shrinking
C.Because frequent mmap/munmap operations can leave gaps in the virtual address space
D.Because each thread must have a separate address space
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Long‑running processes often map and unmap memory regions. When a region is unmapped, the virtual address range becomes a hole. Subsequent allocations may not fit exactly, leaving scattered free slots that cannot be merged, leading to fragmentation. Option A is false; the kernel does reuse pages. Option B is incorrect because processes can shrink their address space via munmap. Option D is unrelated; threads share the same space. Therefore C accurately describes the fragmentation mechanism.

Q21. A daemon repeatedly calls mmap() to allocate 1 MiB buffers and later calls munmap() after processing. Over months of operation, which outcome best describes the effect on the virtual address space lifetime?

A.The address space size will continually increase without bound
B.The address space will stay roughly constant, but internal fragmentation may appear ✅
C.All allocated memory will be leaked, causing the process to crash
D.The address space will be reclaimed completely after each munmap
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Repeated mmap and corresponding munmap keep the total virtual address space size stable because released regions become available for reuse. However, the pattern of allocations can leave small unused gaps, creating internal fragmentation. Option A would require leaks, which are not happening here. Option C describes a leak scenario, not the case. Option D is inaccurate because munmap only frees the physical pages, not the virtual address range for future reuse. Hence B is correct.

Q22. How does Linux’s design of storing file-system, file-descriptor, signal-handler, and virtual‑memory contexts in separate substructures influence the lifetime of a virtual address space after a fork()?

A.The address space can be independently freed while other contexts persist ✅
B.All contexts are freed together, shortening the address space lifetime
C.The fork creates a shared address space that cannot be freed until exec()
D.The separate substructures cause the address space to be duplicated instantly
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Because the kernel isolates each context, the virtual memory area can be released independently of other resources. After fork(), both parent and child have their own virtual memory substructure, and the kernel can deallocate one when its process exits without affecting file-system or signal contexts that may still be needed. Option B is wrong because contexts are not tied together. Option C misstates that fork shares the address space; it uses copy‑on‑write. Option D suggests immediate duplication, which is not true due to lazy copying. Thus A is correct.

Q23. A program uses clone() with CLONE_VM and CLONE_FILES but omits CLONE_FS. If one thread changes its current working directory, what is the impact on the virtual address space of the other thread?

A.Both threads see the new directory, altering their address space layout ✅
B.Only the thread that changed directory sees the effect; the address space remains unchanged for the other
C.The change forces the kernel to duplicate the address space for both threads
D.The address space is freed for the thread that changed directory
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: CLONE_FS controls sharing of file‑system information, including the current working directory. By not setting CLONE_FS, each thread has its own file‑system context, so a directory change affects only the calling thread. The virtual address space, governed by CLONE_VM, is still shared and unchanged. Option A incorrectly assumes directory sharing. Option C suggests unnecessary duplication, which does not occur. Option D is unrelated; changing directories does not free memory. Therefore B accurately describes the behavior.

Q24. Consider a server that continuously spawns new worker processes using fork() followed by execve() to run a handler program. Over time, which statement best reflects the relationship between the lifetime of the original server’s virtual address space and the lifetimes of its children?

A.The server’s address space persists as long as any child process remains alive ✅
B.Each child inherits a copy of the server’s address space that is freed when the child exits, while the server’s own space remains independent
C.The server’s address space is merged with each child’s space, creating a single large address space
D.The server’s address space is destroyed immediately after the first fork
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: When fork() is used, the child receives a copy‑on‑write snapshot of the parent’s address space. After execve(), the child replaces its memory image, freeing the copied pages. The parent’s address space remains untouched and continues to exist until the server itself exits. Option A is false because the parent does not depend on children for its memory. Option C misrepresents merging; no merging occurs. Option D is incorrect because the parent stays alive after forking. Hence B correctly captures the independent lifetimes.

Q25. A programmer wants a new task that shares both memory and open files with the parent process. Which set of clone flags should be used?

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

📖 Explanation: The correct answer is C because CLONE_VM shares the address space and CLONE_FILES shares the file descriptor table, which together give the child task access to the same memory and open files as the parent. Option A only shares memory, not files, so the file descriptors would be separate. Option B only shares files, leaving memory private. Option D shares unrelated resources (filesystem info and signal handlers) but not memory or files, so it does not meet the requirement. In practice, using both flags lets a thread operate on shared data and I/O without extra copying, reducing overhead.

Q26. What is the primary purpose of the Linux clone() system call?

A.To create a new process that shares no resources with the parent
B.To duplicate a thread within the same process
C.To create a new task with selectable shared resources ✅
D.To replace the current process image
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The correct answer is C because clone() is designed to create a new task while allowing the caller to specify which resources are shared with the parent. Option A describes fork(), which does not share resources. Option B suggests duplicating a thread, which is not the primary purpose of clone(). Option D describes execve, which replaces the current process image. Understanding the purpose of clone() helps developers choose the right flags to implement threads or isolated processes as needed.

Q27. Why does Linux treat processes and threads as the same type of task?

A.Because Linux cannot differentiate between processes and threads at the hardware level
B.Because the kernel uses a single data structure for both, making management simpler
C.Because each resource is kept in separate substructures, allowing the kernel to share or duplicate them as needed ✅
D.Because threads are always lighter weight than processes
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The correct answer is C. Linux stores each major resource—memory, file system information, signal handlers, and file descriptors—in separate kernel structures. By pointing a new task to either a private copy or the same structure, the kernel can selectively share resources, making processes and threads appear the same type of task. Options A and B misstate the hardware or simplification reasons, and D is a generic statement about weight that does not explain the kernel’s design. This selective sharing is why threads can be created without copying the whole process.

Q28. If a program calls clone() with no flags, how does the child task behave compared to a fork() call?

A.It shares all resources with the parent
B.It shares only memory with the parent
C.It shares no resources, similar to fork() ✅
D.It shares only file descriptors with the parent
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The correct answer is C. When clone() is invoked without any flags, it does not share any of the parent’s resources, so the child behaves like a process created by fork(): it gets its own memory, file descriptors, and other contexts. Option A incorrectly states that all resources are shared. Option B suggests only memory is shared, which would require CLONE_VM. Option D claims only file descriptors are shared, which would need CLONE_FILES. Recognizing this behavior lets programmers decide whether to use clone() or fork() for isolation.

Q29. A developer notices that after creating a thread with clone(), modifications to the child's file descriptor table affect the parent. Which flag was likely omitted?

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

📖 Explanation: The correct answer is B. If CLONE_FILES is omitted, the child receives a separate file descriptor table, so changes in the child would not affect the parent. Observing the opposite effect indicates that CLONE_FILES was unintentionally included, causing the tables to be shared. Option A (CLONE_FS) relates to the working directory, not file descriptors. Option C (CLONE_VM) concerns memory sharing, and D (CLONE_SIGHAND) deals with signal handlers. Knowing which flag controls file descriptor sharing helps avoid unintended side effects in multithreaded programs.

Q30. How does storing a process’s context in independent subcontexts enable selective resource sharing in Linux?

A.Each resource is copied entirely for every new thread
B.Each subcontext can be either shared or private, so only the desired resources are duplicated ✅
C.The kernel uses a single monolithic context that cannot be partially shared
D.Resource sharing is achieved by copying pointers without any separate structures
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The correct answer is B. By keeping memory, file system context, signal handlers, and descriptor tables in independent substructures, the kernel can decide for each new task whether to point to the existing structure (share) or to create a private copy (duplicate). This design enables fine‑grained control over resource sharing without copying the entire process state. Option A suggests full copying, which would be inefficient. Option C claims a monolithic context, contradicting the modular design. Option D oversimplifies pointer sharing without separate structures. This modularity is the foundation of Linux’s flexible threading model.

Q31. On a memory‑constrained system, a server creates worker threads using clone() with CLONE_VM but without CLONE_FILES. What is the most likely impact on overall memory usage?

A.Memory usage increases because each thread has its own file table
B.Memory usage stays the same because CLONE_VM shares all memory
C.Memory usage decreases because only the memory space is shared ✅
D.Memory usage is unpredictable
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The correct answer is C. Using CLONE_VM makes all threads share the same address space, so only one copy of the program’s memory is needed, reducing overall memory consumption on a constrained system. Not sharing file descriptors (no CLONE_FILES) does not increase memory pressure significantly because descriptor tables are relatively small. Option A would increase memory usage due to separate file tables. Option B is incorrect because CLONE_VM already provides memory sharing. Option D is vague and does not describe the actual impact. Efficient memory use is critical for high‑density servers.

Q32. Suppose a parent task needs to share its current working directory and signal handlers with a child, but keep separate memory spaces. Which combination of clone flags achieves this?

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

📖 Explanation: The correct answer is A. CLONE_FS shares the filesystem information, such as the current working directory, and CLONE_SIGHAND shares the signal handler table, fulfilling the requirement to share those resources while keeping memory private. Option B shares memory and files, which is not desired. Option C shares memory but not signal handlers. Option D shares signal handlers and files, omitting the filesystem information. Selecting the correct combination of flags ensures the child task has the needed shared context without unnecessary duplication, which is essential for proper isolation.

Q33. Which system call creates a new task that shares the memory space with its parent when the CLONE_VM flag is used?

A.clone
B.fork
C.execve ✅
D.vfork
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The clone system call creates a new task, and when the CLONE_VM flag is specified the child shares the same virtual memory area as the parent. Fork always creates a separate memory space, so it does not satisfy the condition. Execve replaces the current image and does not create a new task. Vfork is similar to fork but still gives a separate address space. Therefore the correct answer is clone.

Q34. Why does passing CLONE_FS, CLONE_VM, CLONE_SIGHAND, and CLONE_FILES to clone make it behave like a thread?

A.Because they cause the child to share all major resources with the parent ✅
B.Because they cause the child to duplicate those resources
C.Because they cause the child to isolate those resources
D.Because they cause the child to create separate address spaces
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When all four flags are set, the child task shares the file-system information, memory space, signal handlers, and open file table with the parent. Sharing these resources mirrors the typical thread model where threads run in the same address space and use the same descriptors. The other options describe duplication or isolation, which would not produce thread‑like behavior. Hence the child behaves like a thread.

Q35. Which kernel data structure holds a task's virtual memory context in Linux?

A.task_struct
B.mm_struct ✅
C.file_struct
D.signal_struct
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Linux separates a task's context into independent substructures. The virtual memory information, such as page tables and memory mappings, is stored in the mm_struct, which is referenced from the main task_struct. The task_struct itself contains scheduling and identification fields, while file_struct holds file‑system state and signal_struct contains signal handling data. Therefore the correct answer is mm_struct.

Q36. How does the kernel ensure safe modification of a shared variable when two tasks use CLONE_VM?

A.It uses copy‑on‑write
B.It provides atomic operations automatically
C.It disables preemption while the variable is accessed
D.It relies on user‑space synchronization mechanisms ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: When CLONE_VM shares the same address space, the kernel does not automatically protect data races. The responsibility for mutual exclusion lies with the programmer, who must employ user‑space primitives such as mutexes, spinlocks, or atomic built‑ins. The kernel does not insert copy‑on‑write or disable preemption for arbitrary data, so options A, B, and C are incorrect. Proper synchronization is required for safety.

Q37. A program calls clone with only the CLONE_FILES flag. Which resource is shared between parent and child?

A.Memory space
B.File descriptor table ✅
C.Signal handlers
D.Current working directory
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The CLONE_FILES flag directs the kernel to share the open file table between the parent and child tasks. Memory space remains private because CLONE_VM was not set, so each task has its own address space. Signal handlers are also private without CLONE_SIGHAND, and the current working directory is separate without CLONE_FS. Consequently, the file descriptor table is the shared resource.

Q38. You need two tasks that share memory but have independent file descriptors. Which clone flag set should you use?

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

📖 Explanation: To share the virtual memory area while keeping file descriptor tables separate, only the CLONE_VM flag is required. Adding CLONE_FILES would cause the file tables to be shared, which is not desired. CLONE_SIGHAND shares signal handlers, and CLONE_FS shares file‑system information, neither of which affect descriptor independence. Therefore the correct choice is CLONE_VM alone.

Q39. A parent uses clone with CLONE_VM and CLONE_SIGHAND to run a function that increments a global counter. After the child exits, what is the value of the counter in the parent?

A.It remains unchanged
B.It reverts to its original value
C.It retains the increment made by the child ✅
D.It becomes undefined
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Because CLONE_VM shares the same address space, any modification to a global variable performed by the child directly affects the parent's memory. CLONE_SIGHAND sharing does not alter this behavior. The child's exit does not roll back memory changes, so the increment persists. The variable does not revert or become undefined; it simply reflects the child's update.

Q40. A developer wants a lightweight task that shares everything except the file descriptor table. Which flag should be omitted from the clone call?

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

📖 Explanation: To share all resources except the file descriptor table, the clone call must include CLONE_VM, CLONE_FS, and CLONE_SIGHAND, but must leave out CLONE_FILES. Omitting CLONE_FILES ensures each task has its own descriptor table while still sharing memory, filesystem information, and signal handlers. Including CLONE_FILES would cause the descriptors to be shared, which the developer wants to avoid. Hence the correct answer is CLONE_FILES.

🔗 Related Topics (MCQs)