7,805 views
1 votes
1 votes
How many process are created by the program?
int main(){
    int i;
    for(i=0;i<4;i++)
    fork();
    return 0;
}

Can I write like this ?

fork();

fork();

fork();

fork();

1 Answer

Best answer
5 votes
5 votes

Formula for this fork() related problem is

Total number of process created ={ (2n) -1)+1 }

where { (2n) -1} = number of Child Process  and 1 is for Parent Process. 

Now here fork() is called 4 times .  That means n = 4  .  so put n=4 in above formula we get total number of process created is 16.

Among which 15 =2n - 1 are child process. And 1 is parent process. 

so answer is 16 here .

selected by
Answer:

Related questions

2 votes
2 votes
3 answers
1
Philosophical_Virus asked Dec 10, 2023
870 views
Int main (){fork();printf("a");fork();printf("b");return 0;}How many distinct outputs are possible of above code? And also give outputs
0 votes
0 votes
1 answer
2
Erwin Smith asked Apr 11, 2023
778 views
void main() { int n = 1; if(fork()==0) { n = n<<1; printf(“%d, “, n); n = n <<1; } if(fork()==0) n=n+700; printf(“%d, “,n); }Which of the following output is not ...
0 votes
0 votes
2 answers
4
dd asked Sep 15, 2018
1,060 views
The fork system call creates new entries in the open file table for the newly created child process. [True / False][ what is open file table ? ]