Re: [algogeeks] Re: question on fork()
6 red 10 greens On Wed, Aug 24, 2011 at 9:25 AM, Ankuj Gupta ankuj2...@gmail.com wrote: how can be there 20 greens ? On Aug 24, 12:12 am, DK divyekap...@gmail.com wrote: The standard library is neither multithread safe nor multiprocess safe. If you want the correct answer, use shared memory and maintain a shared counter. Alternatively, as a quick hack, insert a fflush(stdout) after the printf statements. Answer: red() - 6 green() - 20 -- DK http://twitter.com/divyekapoorhttp://gplus.to/divyekapoor -- 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. -- *Shashi Kant * ***Think positive and find fuel in failure* *+919002943948 * *RD engineer , Tejas Networks Ltd Banglore. * -- 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.
Re: [algogeeks] Re: question on fork()
I Can See 10 Green and 10 Red Process.. Can Someone Compile to verify this... Prem On Tue, Aug 23, 2011 at 1:24 AM, gmagog...@gmail.com gmagog...@gmail.comwrote: Infinite times Yanan Cao On Mon, Aug 22, 2011 at 2:43 PM, Don dondod...@gmail.com wrote: // DO NOT RUN THIS! By inspection, how many times will it print Hello world? // If you find out by running it, that is cheating. Don't do it! int main() { int i=0, j=0; for(i = 0; i*j 20; ++i) { if (fork() 0) ++j; else i = j = 0; printf(Hello world\n); } return 0; } -- 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.
Re: [algogeeks] Re: question on fork()
I am getting 6 red and 8 green as expected using the original code Yanan Cao On Mon, Aug 22, 2011 at 2:38 PM, Yasir yasir@gmail.com wrote: Surprisingly, if I comment the last if condition ( which is AFTER red() call ), it is printing red only 6 times as expected.. http://ideone.com/XMHzC main() { fork(); int color=fork(); if(color==0) fork(); red(); //if(color==0) // fork(); green(); getch(); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/1o7KQKelcswJ. 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.
Re: [algogeeks] Re: question on fork()
Infinite times Yanan Cao On Mon, Aug 22, 2011 at 2:43 PM, Don dondod...@gmail.com wrote: // DO NOT RUN THIS! By inspection, how many times will it print Hello world? // If you find out by running it, that is cheating. Don't do it! int main() { int i=0, j=0; for(i = 0; i*j 20; ++i) { if (fork() 0) ++j; else i = j = 0; printf(Hello world\n); } return 0; } -- 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.