At the point of execution of the 4th fork(), there are 8 processes i.e, the 4th fork will get executed 8 times. The final value of ret will depend on this fork. the fork will return 0 in the 8 child processes created and returns pid of the child in the parent processes.
On Mon, Aug 8, 2011 at 12:49 PM, Kamakshii Aggarwal <[email protected]>wrote: > then please elaborate? > > > On Mon, Aug 8, 2011 at 12:34 PM, Pradex <[email protected]> wrote: > >> get it..!! :) :) >> >> On Aug 7, 10:49 pm, Shachindra A C <[email protected]> wrote: >> > 8 one's and 8 two's. The order in which they get printed might vary. >> > >> > On Mon, Aug 8, 2011 at 11:11 AM, Kamakshii Aggarwal >> > <[email protected]>wrote: >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > > what will be the o/p of the following program: >> > >> > > main() >> > > { >> > > int ret; >> > > ret=fork(); >> > > ret=fork(); >> > > ret=fork(); >> > > ret=fork(); >> > >> > > if(!ret) >> > > printf("one"); >> > > else >> > > printf("two"); >> > > } >> > >> > > -- >> > > Regards, >> > > Kamakshi >> > > [email protected] >> > >> > > -- >> > > 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. >> > >> > -- >> > Regards, >> > Shachindra A C >> >> -- >> 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. >> >> > > > -- > Regards, > Kamakshi > [email protected] > > -- > 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. > -- Regards, Shachindra A C -- 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.
