A process executes the following code
for(i=0; i<n; i++) fork();
The total number of child processes created is
View worked solution
Answer: B
To find the total number of child processes created, let us track the total number of active processes after each iteration of the loop.
Initially, before the loop begins, there is only process (the original parent process).
- Iteration 1 (): The existing process calls
fork(), doubling the number of processes to . - Iteration 2 (): Both of these processes call
fork(), doubling the total to . - Iteration : Each of the processes calls
fork(), resulting in processes.
After the loop finishes executing all iterations, the total number of processes running is:
Since the execution started with original parent process, the number of newly created child processes is:
Thus, the correct option is B.
Free practice · Your answers on this page are not saved.
