u r not considering what if the first fork returns non zero and the second for returns a zero value then????
On Aug 31, 9:50 pm, rahul vatsa <vatsa.ra...@gmail.com> wrote: > int main() > { > fork(); > fork() && fork() || fork(); > fork(); > printf("forked\n"); > 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) -- > 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, Aug 31, 2011 at 12:29 PM, SANDEEP CHUGH > <sandeep.aa...@gmail.com>wrote: > > > > > > > > > it will be 16 .. > > > On Wed, Aug 31, 2011 at 9:54 PM, abhishek <abhishek.ma...@gmail.com>wrote: > > >> i think it will be 16 (not sure ) > > >> can anyone explain how it will be 20, > >> On Aug 31, 9:02 pm, SANDEEP CHUGH <sandeep.aa...@gmail.com> wrote: > >> > i thinks it is 16 not 20 > > >> > please check that > > >> > On Wed, Aug 31, 2011 at 9:18 PM, annarao kataru < > >> kataruanna...@gmail.com>wrote: > > >> > > @swathi :: why it is 20 times ?? ur answer is correct but > >> > > plz explain the process?????? > > >> > > -- > >> > > 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.