Interview Question
0of 0 votesresult of this:
main() { fork(); fork(); fork(); printf("hello\n"); }
For Such Cases.We can Calculate the Output by one Formula
(2^(n) -1) + 1
I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.
So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8
Plz ignore Spelling and Grammar Mistakes
sorry for the poor post
1) the parent invokes ffp (i), fp (ii), p
2) Now (i) invokes fp(iii),p
3) (ii) invokes p
4) (iii) invokes another p
There are 7 p's plus the parent prints once. So totally there are 8 "hellos" printed. Forking creates a child process and the excecution of the child process begins following the fork that is used to invoke it. So the output changes if the print statement position changes.
For Such Cases.We can Calculate the Output by one Formula
(2^(n) -1) + 1
I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.
So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8
Plz ignore Spelling and Grammar Mistakes
For Such Cases.We can Calculate the Output by one Formula
(2^(n) -1) + 1
I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.
So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8
Plz ignore Spelling and Grammar Mistakes
For Such Cases.We can Calculate the Output by one Formula
(2^(n) -1) + 1
I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.
So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8
Plz ignore Spelling and Grammar Mistakes
For Such Cases.We can Calculate the Output by one Formula
(2^(n) -1) + 1
I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.
So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8
Plz ignore Spelling and Grammar Mistakes
For Such Cases.We can Calculate the Output by one Formula
(2^(n) -1) + 1
I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.
So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8
Plz ignore Spelling and Grammar Mistakes
For Such Cases.We can Calculate the Output by one Formula
(2^(n) -1) + 1
I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.
So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8
Plz ignore Spelling and Grammar Mistakes

For Such Cases.We can Calculate the Output by one Formula
- User on February 16, 2012 Edit | Flag Reply(2^(n) -1) + 1
I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.
So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8
Plz ignore Spelling and Grammar Mistakes