int main()
{
   fork();
   fork() && fork() || fork();
   fork();

   return 0;
}


ln 1 : will create 2 prs
ln 2 : will create 10 process for each existing pr
ln 3 : will do fork for all 10 process, nd so now u ve 20 prs

the main issue is @ln-2 in main( )

Ln 2 :

here for 1st fork, if its parent, its ret value in nonzero, so it will
proceed for next fork, as that is for &&.  if ret value of this 2nd fork is
nonzero, it willn't try the 3rd fork (as its nt required, bcoz that comes
after ||, nd the st is already a true st) , else 2 prs.  --  > So for parent
of 1st fork in the st, total no of prs created is 3.

if 1st fork returns 0, ie if it is child, it willn't attempt the next fork(bcoz
thatz for operator && , and the st is already 0), bt it will do attempt the
3rd fork(bcoz that is for operator ||)  so total no processes created here
is - 2


Ln 3- this fork is called for all created processes.  2(Ln 1) * 5(ln 2) * 2
(ln 3) == 20 prs





On Wed, Sep 7, 2011 at 12:12 PM, vivek goel <vivek.thapar2...@gmail.com>wrote:

> can anyone explain me how?????????? plsssssssssssssssssss
>
>
> On Wed, Sep 7, 2011 at 9:40 PM, rahul vatsa <vatsa.ra...@gmail.com> wrote:
>
>> 19 prs will be created, total 20 prs.
>>  we have discussed this a few days back. plz check the old thread for any
>> explanation.
>>
>>
>> On Wed, Sep 7, 2011 at 12:01 PM, Mohit Goel <mohitgoel291...@gmail.com>wrote:
>>
>>> a. 15
>>> b. 19
>>> c. 21
>>> d. 27
>>> e. 31
>>> these are the only options.........
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@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 algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@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 algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to