retagged by
17,140 views
24 votes
24 votes

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

retagged by

8 Answers

0 votes
0 votes
From 0 to 9, 0,2,4,6,8 are the values which will satisfy if condition. so fork will be called 5 times. total number of child processes will be 2^5-1=31
0 votes
0 votes
fork is called at 0 , 2 ,4 ,6 ,8 i.e total 5 time

So total number of child is  2^5-1 = 31.
0 votes
0 votes
i is initialized as 0 and it should be incremented by 2 and should go up to less than 10.

consider this code:

                                  for(i=0; i<10; i=i+2)

                                  fork();

fork ( is a function) shall be called 5 times(i=0,2,4,6,8) equal to the no. of even numbers less than 10

∴ Total number of process 2*2*2*2*2 =32 

Total number of child process shall be 32−1=31

reshown by
Answer:

Related questions

25 votes
25 votes
6 answers
1
40 votes
40 votes
4 answers
2
18 votes
18 votes
4 answers
3
13 votes
13 votes
4 answers
4
Arjun asked Feb 7, 2019
9,567 views
Consider the following C program :#include<stdio.h int jumble(int x, int y){ x = 2*x+y; return x; } int main(){ int x=2, y=5; y=jumble(y,x); x=jumble(y,x); printf("%d \n"...