Back to the 2022 paper

Module 2: Processes & Scheduling

20222m

A process executes the following segment of code:

for (i = 1; i <= n; i++)
fork();

The number of new processes created is:

(i) n
(ii) (n(n+1))/2
(iii) 2^n - 1
(iv) 2^n

Worked SolutionAI Assisted

Answer: (iii) 2^n - 1 new processes (2^n total including parent)

Each fork() doubles the number of processes. Loop for i=1..n fork() creates:

after i=1: 2 processes
after i=2: 4 processes
...
after i=n: 2^n processes total

New processes = total - original parent = 2^n - 1. If question counts the parent as well, answer (iv) 2^n is sometimes marked; strictly new = 2^n -1.

Similar questions

Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.