Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  A process executes the following segment of c... Start Learning for Free
A process executes the following segment of code :
for(i = 1; i < = n; i++)
fork ();
The number of new processes created is 
  • a)
    n
  • b)
    ((n(n + 1))/2)
  • c)
    2n - 1
  • d)
    3n - 1
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
A process executes the following segment of code :for(i = 1; i < =...
fork ();     // Line 1
fork ();     // Line 2
fork ();     // Line 3
.....till n
We can also use direct formula to get the number of child processes. With n fork statements, there are always 2n – 1 child processes. Also see this post for more details.
This question is part of UPSC exam. View all Computer Science Engineering (CSE) courses
Most Upvoted Answer
A process executes the following segment of code :for(i = 1; i < =...
Given code segment:
The code segment given is:

for(i = 1; i ≤ n; i++) {
fork();
}

This code segment contains a for loop that iterates from i = 1 to i ≤ n, and for each iteration, it creates a new process using the fork() system call.

Explanation:
Let's analyze the code segment step by step to understand how many new processes are created.

1. Initial iteration (i = 1):
- The first fork() call creates a duplicate process (child process) from the original process (parent process).
- Now, there are two processes (parent and child).

2. Second iteration (i = 2):
- Both the parent and child processes from the previous iteration continue executing the code segment.
- Now, both the parent and child processes execute the fork() call, resulting in each process creating a new child process.
- So, for each of the two processes, two new processes are created.
- Now, there are four processes (two parents and two children).

3. Third iteration (i = 3):
- All the processes from the previous iteration (four processes) execute the fork() call.
- Each process creates a new child process, resulting in eight processes.
- Now, there are eight processes (four parents and four children).

4. Similarly, for the remaining iterations (i = 4 to i ≤ n):
- The number of processes doubles for each iteration.
- For each iteration, the number of processes created is equal to the previous number of processes multiplied by 2.

Total number of processes created:
The total number of processes created can be calculated by summing the number of processes created at each iteration.

Let's consider the number of processes created at each iteration for simplicity:

- Iteration 1: 2 processes
- Iteration 2: 2 * 2 = 4 processes
- Iteration 3: 2 * 2 * 2 = 8 processes
- Iteration 4: 2 * 2 * 2 * 2 = 16 processes
- Iteration 5: 2 * 2 * 2 * 2 * 2 = 32 processes

We can observe a pattern here: the number of processes doubles with each iteration.

So, the total number of processes created is given by the formula: 2^n, where n is the number of iterations (n = 5 in this case).

Therefore, the correct answer is option 'C' - 2n - 1, which is equal to 2^5 - 1 = 32 - 1 = 31.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer?
Question Description
A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer?.
Solutions for A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer?, a detailed solution for A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice A process executes the following segment of code :for(i = 1; i < = n; i++)fork ();The number of new processes created isa)nb)((n(n + 1))/2)c)2n- 1d)3n- 1Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev