π Process creation and termination in operating system (35 MCQs)
Process Lifecycle from Creation to Completion
Process creation and termination are process-management operations through which an operating system introduces new execution activities and releases their resources when they finish. Creation establishes a process identifier, execution context, address space, and required resource relationships. Termination ends execution and initiates resource reclamation. These operations support application launching, multitasking, background services, and coordinated parent-child process relationships.
Reasons for Creating and Removing Processes
New processes arise when users launch applications, running programs request additional execution, or system services start background tasks. Processes terminate after completing their assigned work, encountering fatal errors, or receiving termination requests. The operating system must manage these transitions carefully because unfinished operations, shared resources, and parent-child relationships can complicate cleanup and process accounting.
Process Creation Through Identifiers and Execution Inheritance
In Unix-like systems, fork() creates a child process using a separate process identity and initially inherited execution context. The child may call exec() to replace its process image with another program. The parent can call wait() to collect the child's termination status. The kernel tracks process relationships and releases resources as the lifecycle progresses.
Creating and Waiting for a Child Process
Suppose parent process P creates child C using fork(). Both initially continue from the instruction following the call, receiving different return values. C calls exec() to run a new program, while P calls wait() and may block until C terminates. The kernel records C's exit status and allows P to collect it.
Resource Reclamation, Exit Status, and Process Management
Termination releases process-owned memory, execution resources, and other kernel-managed allocations. In Unix-like systems, a terminated child may remain briefly as a zombie until its parent collects the exit status. An orphan is a child whose parent terminates first; its handling depends on the operating system's process-reparenting mechanism. Improper cleanup can cause resource leaks or excessive process accumulation.
Misconceptions About fork, exec, and Process Termination
'exec() always creates a new process' is incorrect because it replaces the calling process image. 'A child always executes independently from a completely unrelated address space immediately after fork()' is incorrect because implementations may initially use copy-on-write memory. 'A zombie process continues executing' is incorrect because it has terminated and retains only limited bookkeeping information.
Exam Focus: Tracing Parent-Child Process Relationships
Trace process creation using fork(), determine the possible execution paths of parent and child, and identify the role of exec() and wait(). Distinguish normal termination, forced termination, zombies, and orphans. Questions may ask you to count processes after repeated fork() calls, interpret return values, or determine when child resources and termination information are reclaimed.
Key Terms of Process Creation and Termination
- fork() - Creates a child process.
- exec() - Replaces the current process image.
- wait() - Collects child termination information.
- Zombie - Terminated child awaiting status collection.
- Orphan - Child whose parent has terminated.
- Exit status - Reports a process termination result.
π All Process creation and termination in operating system MCQs
Q1. Which system call creates a new process by duplicating the calling process?
π Explanation: The fork system call creates a child process that is a near copy of the parent, including its program and open resources. Both processes then continue from the instruction after the call, and the return value tells each one whether it is the parent or the child.
Q2. Which system call replaces the memory image of the current process with a new program?
π Explanation: The exec system call loads a new program into the existing process, discarding the old program's code, data and stack. The process keeps its identifier, so exec changes what the process runs rather than creating a new process, which is a key distinction when reasoning about process creation.
Q3. Which system call allows a parent process to wait for a child to finish and retrieve its exit status?
π Explanation: The wait call suspends the parent until one of its children terminates and returns the child's exit status. Collecting this status also releases the resources kept for the terminated child, so calling wait is the normal way for a parent to synchronise with and clean up after its children.
Q4. What is a process called when it has terminated but its exit status has not yet been collected by its parent?
π Explanation: A zombie retains only a small entry in the process table so that the parent can read the exit status later. It uses no CPU or memory for execution, but its entry remains until the parent calls wait. Many zombies usually indicate a parent that fails to collect its children.
Q5. What is a child process called when its parent terminates before the child does?
π Explanation: An orphan is a child whose parent has ended. Operating systems typically reassign orphans to a system process such as init, which becomes their new parent. This adoption ensures that someone remains responsible for collecting the orphan's exit status when it finally terminates.
Q6. A student believes that exec creates a new process with a new process identifier. Which correction is most accurate?
π Explanation: When a process calls exec, its identifier and parent relationship remain the same, but the code, data and stack are replaced by the new program. Creating a new process is the job of fork. Confusing the two calls leads to mistaken assumptions about process trees and identifiers.
Q7. Why does fork return different values to the parent and the child?
π Explanation: After fork, both processes run the same code, so the return value is the only way to distinguish them. The parent receives the child's identifier, while the child receives zero. Programs branch on this value so that each process performs its own role after creation.
Q8. Why must a parent normally call wait for its children?
π Explanation: When a child terminates, its exit status is kept until the parent collects it. Calling wait frees that entry and reports the result. Without this call, terminated children accumulate as zombies, consuming process table slots, which is why well-behaved programs always collect their children.
Q9. Why does the operating system adopt an orphan process under the init process, rather than leaving it without a parent?
π Explanation: Every process needs a parent to eventually collect its exit information and keep the process tree consistent. Reassigning orphans to init provides that responsibility, so terminated orphans do not accumulate as unmanaged zombies, which would otherwise waste process table space.
Q10. Why does copy-on-write make fork efficient?
π Explanation: Copying all memory at fork time would be slow and wasteful, especially when the child immediately calls exec. With copy-on-write, pages are shared until modified, so the cost of duplicating data is paid only for pages that actually change. This makes fork practical even for large processes.
Q11. After a fork, why does a change to a variable in the child not affect the parent's copy of that variable?
π Explanation: Although copy-on-write shares pages initially, a write causes the affected page to be copied so that each process has its own version. The address spaces are logically separate, so changes made by one process are invisible to the other, which is essential for correct isolation.
Q12. Why does termination of a parent not necessarily terminate its children on many systems?
π Explanation: A child is a separate process, and most systems let it continue after the parent exits, leading to orphan status. Some systems enforce cascading termination, which ends all descendants along with the parent. The behaviour is therefore a policy decision, not an automatic consequence of process creation.
Q13. A process has terminated and its exit status is recorded in the process table. Why does the operating system keep this entry until the parent collects it?
π Explanation: The exit status tells the parent how the child finished, which may affect the parent's next actions. Keeping the minimal entry until it is read preserves this information. Once collected, the entry is released so that the table space can be reused for new processes.
Q14. A program calls fork unconditionally three times in sequence in the same process. How many processes exist after these calls, including the original?
π Explanation: Each fork doubles the number of processes because every existing process creates one new copy. After three forks, the count is , including the original. Recognising this exponential growth is important when reasoning about loops that create processes, since they can quickly exhaust system resources.
Q15. A program executes the statement fork followed by fork, unconditionally, and every process then prints one line. How many lines are printed?
π Explanation: The first fork produces two processes, and the second fork doubles them to four, so four lines are printed. Each process executes the same code after fork, so the count follows the doubling pattern. Careful tracing of each call is essential for this kind of multi-step reasoning.
Q16. A shell creates a child to run a command. Which sequence of system calls is typically used?
π Explanation: The shell calls fork to create a child, the child calls exec to load the command's program, and the shell calls wait to pause until the command finishes. This standard sequence lets the shell launch commands while retaining control, and it explains why fork and exec are usually used together.
Q17. After a fork, the parent sets a variable x to 5 and the child then sets its own copy of x to 10. What value does the parent see for x afterward?
π Explanation: The child's assignment changes only the child's copy, so the parent still holds 5. Each process has its own address space, and writes are not shared even though memory pages may initially be shared. This isolation is a key property that makes process-based concurrency predictable.
Q18. A child process exits with status 3 and the parent calls wait. What value does wait report for the child's exit status?
π Explanation: When the child terminates with status 3, the parent receives this value through wait, which lets it interpret the outcome. By convention a status of zero indicates success, while nonzero values signal specific failures. The exit status is the information carried from the child to the parent.
Q19. A process tree has P1 with children P2 and P3, and P2 has child P4. Under a cascading termination policy, P2 is terminated by the operating system. Which processes terminate as a result?
π Explanation: Cascading termination ends a process together with all of its descendants, so terminating P2 also ends its child P4. P1 and P3 are not descendants of P2, so they continue. Identifying the subtree correctly is the key step in deciding which processes are affected by the termination.
Q20. Which value does fork return to the child process when it succeeds?
π Explanation: On success, fork returns zero to the child and the child's identifier to the parent. The zero return value lets the child recognise that it is the new process. Checking this return value is the standard way that programs decide which branch of code each process should follow.
Q21. A student says that a zombie process is still executing and consuming CPU time. What is the error in this reasoning?
π Explanation: A zombie has finished executing and holds no CPU time. Its entry remains only to store the exit status for the parent. The student confuses the terminated state with an active one, which misreads what the presence of zombies indicates about the system.
Q22. A student says that when a parent calls exec, the parent is replaced by a new process with a different identifier. What is wrong with this claim?
π Explanation: The exec call changes the code and data of the calling process while keeping its identifier and relationships. Creating a new process is done by fork. The student merges these two distinct operations, which leads to wrong conclusions about identifiers and process trees.
Q23. A student says that after fork, parent and child share the same memory, so writes by either process are visible to both. Which correction is most accurate?
π Explanation: Copy-on-write shares pages initially for efficiency, but a write triggers a private copy for the writing process. The address spaces are logically separate, so the student's conclusion about permanent visibility of writes is incorrect and would lead to serious errors in program reasoning.
Q24. A student says that a parent need not call wait because the operating system always cleans up terminated children automatically. What is the error?
π Explanation: The operating system keeps the exit information until a parent reads it, so cleanup depends on the parent's wait call. Programs that never call wait accumulate zombies, consuming process table entries. The student's claim ignores this responsibility that the parent has in the termination protocol.
Q25. A student says that when a parent terminates, its orphan children are deleted immediately. Which evaluation is most accurate?
π Explanation: Operating systems normally reassign orphans to init or an equivalent system process, which then becomes their parent. The orphans continue executing normally. Assuming they are deleted misunderstands the adoption mechanism that preserves the process tree's integrity.
Q26. A process tree shows the shell (PID 100) with three descendants: editor (PID 200), compiler (PID 201) and linker (PID 202), where the linker is a child of the compiler. How many descendants does the shell have in total?
π Explanation: The descendants of the shell include every process created beneath it, namely the editor, the compiler and the linker. The linker is a child of the compiler but still counts as a descendant of the shell. Counting all levels of the tree rather than only direct children is the key point.
Q27. A table records a child process with status Z from time 5 to time 20 while its parent remains sleeping and never calls wait. What does this record most likely indicate?
π Explanation: Status Z denotes a zombie, a terminated process whose entry remains until the parent calls wait. Since the parent is sleeping and never collects the status, the entry persists for the entire interval. The record is therefore best explained by a zombie rather than normal execution.
Q28. A bar chart shows the number of processes after 1, 2, 3 and 4 fork iterations as 2, 4, 8 and 16. What is the best inference?
π Explanation: The bars double with each iteration, which is the signature of exponential growth. Unbounded forking inside loops can therefore consume process table entries and memory rapidly, which is why programs must control how many processes they create.
Q29. A line graph shows the memory used by a newly forked child over time. It stays near zero for a long period, then rises in steps as the child writes to its variables. What does this pattern suggest?
π Explanation: The flat start indicates that pages are shared rather than copied at fork time. The steps occur when the child writes to variables and private copies of the affected pages are created. The graph therefore matches the copy-on-write strategy, which defers copying until necessary.
Q30. A graph compares the time to create a process using a full copy of memory against copy-on-write, across different memory sizes. Copy-on-write stays nearly constant while full copying grows with memory size. What is the best inference?
π Explanation: The flat line for copy-on-write shows that the immediate cost does not grow with memory size, while full copying rises steadily. The inference is supported because the data compares the two methods across sizes, illustrating why modern systems favour copy-on-write for fork.
Q31. Which combination correctly describes how a new program is run in a new process on a typical system?
π Explanation: Running a new program in a new process combines two steps: fork creates the child, and the child uses exec to replace its image with the desired program. The other sequences reverse or misassign the roles of these calls, so they fail to create a separate process running the new program.
Q32. Which pairing correctly links a parent's call with its effect on the child's exit status?
π Explanation: The wait call is the mechanism by which a parent collects the child's exit status and allows the entry to be released. The other pairings assign the wrong effect to exec, fork or exit, so they do not describe how the exit status is transferred from child to parent.
Q33. Which situation leaves a zombie process in the system?
π Explanation: A zombie arises when a child has ended but its parent has not yet collected the exit status, so the entry persists. The other situations involve normal execution, waiting for an active child, or adoption by init, none of which leave a terminated entry uncollected.
Q34. A program calls fork in a loop so that every existing process forks once per iteration, for 5 iterations, starting from one original process. Including the original, how many processes exist at the end?
π Explanation: Each iteration doubles the number of processes, so after 5 iterations the count is , counting the original. The pattern shows that loops of fork calls grow exponentially. Forgetting that every process participates in each iteration, or counting only the newly created ones, leads to the smaller incorrect totals.
Q35. Process P (PID 300) forks child C (PID 301), and C forks grandchild G (PID 302). P exits, and then C exits before G finishes. What is the parent of G after C exits?
π Explanation: When C exits, G is orphaned, and the operating system reassigns it to init, which has PID 1 in typical systems. P's identifier 300 and C's identifier 301 are no longer valid parents of G at that point. Following the adoption rule step by step is the key to answering this multi-step scenario.