and on running this code the process is printd 17 times, how is the
answer 19??????im getting 31(including the initial process).....plz
explain.....

On Sep 6, 7:07 am, PremShankar Kumar <[email protected]> wrote:
> @Sachin, @Mohit:-
>
> You are right 19 new processes will get created. Thanks guys.
>
> #include <unistd.h>
> #include<iostream>
>
> using namespace std;
>
> int Fork(int i)
> {
>           //cout<<endl<<"Fork"<<i<<" executed."<<endl;
>           return fork();}
>
> int main()
> {
>            Fork(1);
>            Fork(2) && Fork (3) || Fork (4);
>            Fork (5);
>            cout<<endl<<"Process\n";}
>
> Regards,
> Prem
>
>
>
> On Sun, Sep 5, 2010 at 9:35 PM, sachin <[email protected]> wrote:
> > Yes, you are right mohit, the no of processes is indeed 20.
> > but the question asks for the no of new processes created, not the
> > total no of processes.
> > Hence, we subtract the initial process from the final ans, we get 19.,
> > which is the required answer...:-) :-)
>
> > On Sep 4, 11:10 pm, "MOHIT ...." <[email protected]> wrote:
> > > Fork() && fork () || fork ();
> > > Fork return 0 in child process and non-zero in parent
> > > so in child process Fork()&& only executed not fork()||fork();(&& stop
> > > working if get 0 as previous input);
>
> > > if we get parent after parent only fork of (&& ) and initial fork of ||
> > get
> > > executed;(|| stops if one input is 1 next one not evaluated).
>
> > > if we get child after parent whole fork && fork()|| fork() get executed.
>
> > > but answer comes 20.
> > > plz correct me if i am wrong
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<algogeeks%2bunsubscr...@googlegroups 
> > .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to