GateAI
Processes, Threads and IPC

GATE CSE 2019 · Q17

NAT1 markEasy

Time

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 _______.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 31

Processes, Threads and IPC

The for loop iterates for i=0,1,2,…,9i = 0, 1, 2, \dots, 9.

The condition i % 2 == 0 evaluates to true when i∈{0,2,4,6,8}i \in \{0, 2, 4, 6, 8\}, which is a total of 55 times.

Each time fork() is called, all existing processes create a new child process, effectively doubling the total number of processes.

  • Total processes after 55 fork() calls =25=32= 2^5 = 32.

  • Since 11 process is the original parent process, the total number of child processes created is:

25−1=32−1=312^5 - 1 = 32 - 1 = 31

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Processes, Threads and IPC previous year question is Q17 of the GATE CSE 2019 paper. Find more GATE CSE PYQs on Processes, Threads and IPC in Operating Systems, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Processes, Threads and IPC PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Processes, Threads and IPC in GATE CSE

Processes, Threads and IPC has 15 GATE CSE PYQs across 13 papers from 2011 to 2026. 3 of them are 1-mark NAT questions like this one, and GATE CSE 2019 has 2.

How GATE tests Processes, Threads and IPC

More from GATE CSE 2019

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2019 · Q17 · NAT

The following C program is executed on a Unix/Linux system: #include int main() { int i; for (i=0; i The total number of child processes created is …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.