Assess your understanding of process creation, process termination, and process management using fork, exec, and wait system calls. This quiz covers fundamentals, real-world scenarios, and key behaviors important for operating systems and programming.
What is the primary purpose of the fork system call in operating systems?
Explanation: The fork system call is used to create a new process by duplicating the calling (parent) process, resulting in a child process with its own process ID. It does not terminate processes, which is done by exit, nor does it replace process memory or programs, which is handled by exec. Pausing a process is not the purpose of fork.
After a fork call, what does the returned value indicate to the parent and child process?
Explanation: After fork, the return value is 0 in the child process and the child’s process ID in the parent. This distinction allows each process to determine its role. Returning -1 indicates fork failed, not process identity. Option B correctly describes this behavior while the other options swap values or reference incorrect identifiers.
When a process calls an exec family function, what happens to its existing code and data?
Explanation: Using exec replaces the current process’s memory (code, data, and stack) with the new program’s image. The original memory and code are not kept or copied, nor are they paused or run alongside the new program. Options A and D are incorrect as the original content does not remain or pause; option C is inaccurate since exec does not create a new process.
Why might a parent process use the wait system call after creating a child process?
Explanation: The wait call allows the parent to obtain the child process’s exit status and remove the child process entry, preventing zombies. It does not affect the execution speed or resource duplication, and does not directly free memory; memory is freed when the process exits and wait is called. Other options do not match wait’s purpose.
What value does fork return if it fails to create a new process?
Explanation: Fork returns -1 on failure, indicating an error in creating a new process. A return value of 0 signals a successful child process, while 1 and NULL are not standard fork return values. The others are realistic but incorrect for fork’s error reporting.
Immediately after a successful fork, how many separate processes are running?
Explanation: A successful fork results in two processes: the parent and the newly created child, both executing independently. One process would mean fork did not happen, while three is possible only if multiple forks occur. Zero indicates no processes, which is not the case after a successful fork.
What is a zombie process in the context of process termination?
Explanation: A zombie process has terminated but continues to occupy a process table slot because its parent hasn’t retrieved its exit status, usually via wait. It is not an infinite loop, unkillable system process, or a duplicate. The other options describe different process issues but not zombies.
Does calling an exec family function change the process identifier (PID) of a process?
Explanation: Exec replaces the program image but does not change the process ID. The PID remains the same since only the code and data change, not the process identity. Assigning a new PID or resetting it is incorrect, and the PID does not become the parent’s PID.
After a fork, which of the following is shared between parent and child processes?
Explanation: File descriptors open at the time of fork are inherited by the child, meaning both parent and child can access open files. The process IDs are unique, address spaces are independent, and stack pointers are different after the fork. Only file descriptors among these are shared.
To run a different program in a child process after a fork, what is the recommended sequence of system calls?
Explanation: First, fork creates a child process. Then, the child uses exec to run a different program. Reversing this order or combining with wait in the wrong sequence is incorrect; wait is usually used by the parent after the child starts. Fork followed by exec is the standard and recommended sequence.