GATE CSE 2019 Q27: fork() inside loop for even i from 0 to 9: number of child processes
- Operating System
- 1 mark
- NAT
- No negative marking
Syllabus topic: System calls, processes and threads
Question
The following C program is executed on a Unix/Linux system:
#include <unistd.h>
int main()
{
int i;
for (i=0; i<10; i++)
if (i%2 == 0) fork();
return 0;
}The total number of child processes created is ________.
Try it: numerical answer: type the value
Numerical answer. No negative marking.
Show answer and explanation
Answer: 31 (official GATE 2019 final answer key)
Concept used: Each fork() doubles the number of processes, so sequential forks create child processes.
First step: Count how many times fork() is actually executed along one path (only for even ), then use .
Full step-by-step solution
Loading…
Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.
More questions on System calls, processes and threads
Every PYQ on this topic →Share this question
Source: official GATE 2019 CS question paper and final answer key, organised by IIT Madras. Question paper · Answer key
More Operating System PYQs
- 2026 Session 1 · Q29False statements about deadlocks
- 2026 Session 1 · Q35Minimum resource instances for deadlock freedom (5 processes, max 2)
- 2026 Session 1 · Q59Disk transfer time for random sectors on tracks 5, 12, 7
- 2026 Session 1 · Q63Number of printf calls with fork, continue and break
- 2026 Session 1 · Q64Average FCFS waiting time for alternating A and C processes
- 2026 Session 2 · Q23CPU scheduling algorithm that cannot be preemptive