Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
464 views
in Computer by (88.5k points)
closed by

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

1 Answer

0 votes
by (85.4k points)
selected by
 
Best answer

Value of i

fork calling

0

Called

1

not called

2

Called

3

not called

4

Called

5

not called

6

Called

7

not called

8

Called

9

not called

From the table it is clear that fork is called 5 times

Formula:

If n times fork is called the number of child processes created = 2n - 1

Since n = 5 in the given code then number of child processes created = 25 - 1 = 31

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...