📝 Execution and Loading of User Programs in The Linux System (24 MCQs)
Starting Executable Programs in Linux User Space
Linux program execution begins when a process requests execution of a program through an interface such as execve(). The kernel identifies and loads a supported executable format, establishes the new process memory image, and prepares its initial execution context. For common ELF applications, loading may involve mapped executable segments, a user stack, and a dynamic linker.
Why Executable Loading Requires Memory and Linking Setup
Executable files contain code, data, and metadata that must be mapped into a process address space. Dynamically linked programs also depend on shared libraries whose locations and symbols must be resolved. The kernel and user-space runtime divide these responsibilities so the application starts with valid code, data, arguments, and environment variables.
ELF Loading and Dynamic Linker Operation
The kernel recognises the executable format and maps required ELF loadable segments with appropriate permissions. It prepares arguments, environment data, and the initial stack. For a dynamically linked binary, control passes through the program interpreter, usually the dynamic linker, which maps libraries and resolves required symbols before application execution.
Example of Launching a Dynamically Linked Program
A shell launches an ELF executable named report. The process receives arguments and environment variables, while the kernel maps its code and data segments. The ELF interpreter loads required shared libraries and performs relocation. Execution then begins at the program's entry point, which leads into normal runtime startup.
Demand Loading, Relocation and Startup Costs
Mapped executable segments allow pages to be brought into memory as they are accessed rather than loading the entire file immediately. Shared libraries reduce duplicated code across processes but create dependency requirements. Missing libraries, invalid executable metadata, or permission errors can prevent startup, while dynamic linking introduces runtime loading and symbol-resolution work.
Misconceptions About Linux Program Loading
'execve() creates a second process' is false because it replaces the caller's process image. 'The kernel loads every executable byte into RAM at once' ignores demand paging. 'Dynamic libraries are loaded entirely by the kernel' overlooks the user-space dynamic linker and its symbol-resolution responsibilities.
Exam Focus: ELF Segments and Process Startup
Trace execve(), ELF recognition, memory mapping, stack preparation, and dynamic linking. Distinguish program headers from runtime library loading. Questions may examine arguments, environment variables, entry points, shared libraries, relocation, or why a valid executable can still fail when a required interpreter or library is missing.
Key Terms of Linux Program Loading
- execve() - Replaces a process image with a program.
- ELF - Executable and Linkable Format.
- Program segment - Mapped region defined by executable metadata.
- Dynamic linker - Loads and links shared libraries.
- Entry point - Initial address for program execution.
📝 All Execution and Loading of User Programs in The Linux System MCQs
Q1. What system call creates a new process by duplicating the calling process without loading a new executable image?
📖 Explanation: The fork() call duplicates the current process, creating a child that starts execution at the same point but with its own copy of the parent’s memory and resources. execve() replaces a process image, clone() can create threads or processes depending on flags, and wait() merely pauses the parent. Therefore fork() is the only call that matches the description, making it the correct choice. The other options either load a new program or perform unrelated actions.
Q2. How does the behavior of clone() differ from fork() when no sharing flags are specified?
📖 Explanation: When clone() is invoked without any CLONE_* flags, it does not share resources with the parent, so it creates a new task that is functionally equivalent to a process created by fork(). It does not automatically share memory or act as a thread, and it does not fail; it succeeds in creating a separate task. Thus the correct answer is that clone() behaves like fork() under these conditions, while the other statements mischaracterize its behavior.
Q3. Which effect does setting the flag have on the child task created by clone()?
📖 Explanation: The flag tells the kernel to let the child task use the same virtual memory area as the parent, meaning both tasks see identical memory contents and changes made by one are visible to the other. This is the defining characteristic of a thread‑like relationship. The other options describe copying, denial of access, or separate address spaces, none of which occur when is set.
Q4. A developer wants to create a thread‑like task that shares the current working directory, memory, signal handlers, and open files with its parent. Which combination of flags should be passed to clone()?
📖 Explanation: To obtain full thread‑like sharing, the developer must request sharing of the filesystem information (), the memory space (), the signal‑handling table (), and the file descriptor table (). Only the combined flag set provides all four shared resources. Supplying any single flag would share just one aspect, so the combined flag expression is the only correct answer.
Q5. A program needs separate address spaces for parent and child but wants them to share the set of open files. Which set of flags should be used with clone()?
📖 Explanation: Separating address spaces means the child must not inherit the parent’s memory, so the flag must be omitted. To keep the open file descriptors shared, the flag is required. Using no flags would give completely independent resources, while the other options either share memory or unrelated resources. Therefore the correct choice is the single flag.
Q6. After creating a child task with clone() using the flag, the parent installs a new signal handler for SIGINT. What is the expected behavior in the child task?
📖 Explanation: The flag causes the parent and child to share the same signal‑handler table. Consequently, any modification to a handler in the parent—such as installing a new handler for SIGINT—immediately becomes visible to the child. The child does not retain the old handler, nor does it revert to the default action, and there is no crash solely due to the shared table. Hence the child sees the newly installed handler.
Q7. Why does Linux treat processes and threads as the same type of object called a task?
📖 Explanation: Linux’s kernel design separates a task’s various contexts—file‑system, memory, signal handlers—into independent data structures. This modular approach lets the scheduler treat both processes and threads uniformly as tasks, while the presence or absence of shared substructures determines whether they behave like independent processes or thread‑like entities. The other statements are inaccurate: Linux fully supports threads, processes can share memory with appropriate flags, and clone() provides an alternative to fork().
Q8. A program calls fork() and then execve() in the child to run a different executable. If the programmer instead used clone() with no flags, which of the following would be true about the child before execve()?
📖 Explanation: When clone() is invoked without any CLONE_* flags, it behaves like fork(): the child receives its own copies of all resources, including a distinct signal‑handler table. Therefore the child does not share signal handlers with the parent. While the child also has separate memory and file descriptors, the statement about its own signal handler table directly addresses the question’s focus, making it the correct answer. The other options incorrectly claim sharing of memory or file descriptors.
Q9. Which flag causes the child created by clone() to share the same memory space as the parent?
📖 Explanation: The flag tells the kernel to let the child task use the same virtual memory area as its parent. Because the memory pages are shared, changes made by one task are visible to the other, which is the defining behavior of a thread. The other flags only affect filesystem information, signal handlers, or open file tables, so they do not cause memory sharing. Therefore the correct answer is .
Q10. Why does Linux treat threads and processes as tasks rather than separate entities?
📖 Explanation: Linux represents every execution flow as a task because the kernel keeps the various parts of a context—such as the file‑system view, memory map, and signal table—in independent structures. This design lets the kernel decide which parts to share when a new task is created, turning a clone into a thread or a fork into a separate process. By using a single task type, the scheduler and accounting code remain simple, and resources can be shared or isolated flexibly. Hence the correct answer is that Linux stores each context component in separate substructures, enabling selective sharing.
Q11. How does the presence of the flag affect signal handling between a parent and its child created with clone()?
📖 Explanation: When is specified, the kernel makes the child task point to the same signal‑handler table as the parent. Any modification to a handler in one task instantly changes it for the other, because both refer to the identical data structure. Without this flag, each task receives a private copy of the handler table, so changes remain isolated. The other options describe behaviours that do not occur with . Thus the correct answer is that signal handlers are shared, causing changes in one to affect the other.
Q12. A programmer wants to create a thread that shares memory and signal handlers with the parent but keeps its own set of open files. Which combination of clone() flags should be used?
📖 Explanation: To share the address space, the flag is required, and to share the signal‑handler table, the flag must be set. Because the requirement is to keep a private file‑descriptor table, the flag must be omitted. Option C contains exactly the two needed flags and excludes the file‑sharing flag, while the other options either add unwanted sharing or miss a required flag. Therefore the correct answer is the combination | .
Q13. To implement a high‑performance web server that spawns a new thread for each incoming connection, which system call and flag set provides the best balance of isolation and shared resources?
📖 Explanation: A web server needs each connection to have its own socket descriptor, so the file‑descriptor table should not be shared. Sharing the memory space allows common data such as configuration or caches to be accessed without copying. The minimal flag set that achieves this is alone; it provides a shared address space while keeping file tables separate. Adding or would unnecessarily couple file descriptors or signal handling across threads, and using fork would incur higher overhead. Hence the correct answer is clone() with only.
Q14. During debugging, a segmentation fault occurs in a program that uses clone() to create worker threads, but the programmer omitted a crucial flag causing the threads to have separate address spaces. Which flag should be added to fix the fault?
📖 Explanation: If the threads do not share the same virtual memory area, any pointer that one thread writes to may refer to an unmapped region in the other, leading to a segmentation fault. Adding the flag makes both tasks use the same memory map, so they operate on the same pages and the fault disappears. The other flags affect filesystem views, signal handlers, or file tables, none of which resolve address‑space mismatches. Therefore the correct answer is to include the flag.
Q15. Explain why Linux can implement both processes and threads using the same underlying data structures, and what advantage this design gives for resource management.
📖 Explanation: Linux's kernel keeps the file‑system state, memory map, signal table, and other components in separate data structures. When a new task is created, the kernel can choose to point the child to the same structures (creating a thread) or to allocate fresh copies (creating a process). This unified representation simplifies the scheduler, reduces code duplication, and enables fine‑grained control over which resources are shared or isolated, improving performance and flexibility in resource management. The other statements misrepresent how Linux stores context or its capabilities. Hence the correct answer is that Linux separates each context component into independent substructures, allowing selective sharing.
Q16. A system administrator wants to run a legacy application that expects separate processes but also wants to limit memory usage by sharing code pages among instances. Which clone() flag combination should be used to meet both requirements?
📖 Explanation: The legacy application expects each instance to have its own private data, which is naturally provided by fork() because the kernel uses copy‑on‑write for the address space, allowing code pages to be shared while data pages remain separate. No clone() flag set can mimic this behavior without also sharing the entire memory space, which would break isolation. Therefore the safest and most appropriate method is to use fork() without additional flags, as described in option D. The other options would either share all memory or add unnecessary sharing, violating the requirement for separate processes.
Q17. What is the primary difference between static and dynamic linking?
📖 Explanation: Static linking embeds the entire library into the final binary, so the program contains its own copy of needed functions. This makes the executable larger but independent of external files. Dynamic linking keeps the executable small and resolves symbols when the program runs, pulling code from shared libraries. Options B and C confuse the timing of symbol resolution, while D reverses the roles of the two techniques.
Q18. Why might a developer choose dynamic linking for a large application?
📖 Explanation: Dynamic linking reduces executable size because the code resides in shared libraries rather than being copied into each binary. This also allows multiple programs to share the same library code in memory, saving RAM. The other options are incorrect: dynamic linking does not guarantee library versions (that depends on deployment), it still uses a linker, and it does not affect compilation speed directly.
Q19. How does dynamic linking affect memory usage when several programs use the same library?
📖 Explanation: When a shared library is dynamically linked, the operating system maps the same physical pages of the library into the virtual address spaces of all processes that need it. Consequently, only one copy resides in RAM, which is shared, reducing overall memory consumption. Options A and D describe static linking behavior, while C incorrectly claims no impact on memory.
Q20. A developer must distribute a Linux program that runs on machines with varying versions of libssl. Which linking strategy should they use?
📖 Explanation: Choosing dynamic linking while relying on the system's libssl allows the program to use the version already present, avoiding compatibility issues across machines. Bundling a specific version defeats the purpose of handling varying versions. Statically linking libssl would embed a single version, potentially incompatible with other system components. The best approach is to dynamically link and let the system provide the appropriate library.
Q21. A program fails to start because it cannot find libfoo.so at runtime. Which action will most likely fix the problem?
📖 Explanation: Setting LD_LIBRARY_PATH tells the dynamic loader where to search for shared libraries, so adding the directory with libfoo.so resolves the missing library error. Recompiling with static linking would avoid the need for the shared library but requires source changes. Renaming to a static library (.a) does not help a dynamically linked binary, and deleting the executable does not address the library search path.
Q22. A security audit finds that a statically linked program contains an outdated OpenSSL function. What is the most effective way to mitigate the risk without rebuilding the whole program?
📖 Explanation: Using LD_PRELOAD allows a newer OpenSSL shared library to be loaded before the program’s own symbols, effectively overriding the vulnerable function without recompiling. This technique works because the program was statically linked, but the loader can still interpose shared objects. Direct binary patching is error‑prone, removing the function requires source changes, and converting to dynamic linking would also require recompilation.
Q23. Explain how symbol resolution differs between statically and dynamically linked executables at load time.
📖 Explanation: In a statically linked binary, every external reference is resolved during compilation, so the executable contains concrete addresses for all functions and data. A dynamically linked executable, however, leaves some symbols undefined; the dynamic loader (ld.so) examines the program’s relocation tables at startup, finds the needed shared libraries, and binds those symbols to actual memory addresses. Options A and D misstate when resolution occurs, and B incorrectly claims static binaries lack symbol resolution entirely.
Q24. A system needs to load optional plugins at runtime. Which linking mechanism best supports this requirement?
📖 Explanation: Loading plugins on demand is most naturally handled by dynamic linking with functions like dlopen, which can load shared objects while the program is running. This approach allows new modules to be added without recompiling the main binary. Static linking would require rebuilding the executable for each new plugin, and loading at program start defeats the purpose of runtime extensibility. Therefore, dynamic linking with runtime loading (option D) is the optimal solution.