[algogeeks] Re: fork()

2011-09-01 Thread htross
ya got it thanx. On Sep 1, 12:46 pm, rahul vatsa wrote: > *Ln 2 :1st fork ret value +ve, (i.e parent), * > As && is their before next fork, so nw 2nd fork will be calld, >         if (ret >= 0), won't go for next fork, (as its a true for ||) => so > 1 pr from here >         else if (ret ==0)

Re: [algogeeks] Re: fork()

2011-09-01 Thread rahul vatsa
*Ln 2 :1st fork ret value +ve, (i.e parent), * As && is their before next fork, so nw 2nd fork will be calld, if (ret >= 0), won't go for next fork, (as its a true for ||) => so 1 pr from here else if (ret ==0), will go for next fork. => so 2 prs from here so, total 3 process in c

Re: [algogeeks] Re: fork()

2011-09-01 Thread Pratz mary
this s on geeks for geeks and the answer is 20 On 1 September 2011 00:11, htross wrote: > 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 wrote: > > int main() > > { > >fork(); > >fork() &

[algogeeks] Re: fork()

2011-08-31 Thread htross
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 wrote: > int main() > { >    fork(); >    fork() && fork() || fork(); >    fork(); >    printf("forked\n"); >    return 0; > > } > > ln 1 : will create 2 pr

Re: [algogeeks] Re: fork()

2011-08-31 Thread rahul vatsa
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 1

Re: [algogeeks] Re: fork()

2011-08-31 Thread rohit
Someone please provide the recursion tree for it..thanks -- 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/-/_o5nQen8VmAJ. To post to this group, send email to

Re: [algogeeks] Re: fork()

2011-08-31 Thread rajeev bharshetty
I ran the code on gcc and the answer is 20 times On Wed, Aug 31, 2011 at 9:59 PM, SANDEEP CHUGH wrote: > it will be 16 .. > > On Wed, Aug 31, 2011 at 9:54 PM, abhishek 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

Re: [algogeeks] Re: fork()

2011-08-31 Thread SANDEEP CHUGH
it will be 16 .. On Wed, Aug 31, 2011 at 9:54 PM, abhishek 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 wrote: > > i thinks it is 16 not 20 > > > > please check that > > > > On Wed, Aug 31, 2011 at 9:18 PM, annarao ka

Re: [algogeeks] Re: fork()

2011-08-31 Thread Swathi
Can someone run and provide the answer... On Wed, Aug 31, 2011 at 9:54 PM, abhishek 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 wrote: > > i thinks it is 16 not 20 > > > > please check that > > > > On Wed, Aug 31, 20

[algogeeks] Re: fork()

2011-08-31 Thread abhishek
i think it will be 16 (not sure ) can anyone explain how it will be 20, On Aug 31, 9:02 pm, SANDEEP CHUGH wrote: > i thinks it is 16 not 20 > > please check that > > On Wed, Aug 31, 2011 at 9:18 PM, annarao kataru > wrote: > > > > > > > > > @swathi ::  why  it is  20  times ??   ur answer  is  

[algogeeks] Re: Fork

2011-08-17 Thread siva viknesh
search in this group itself .. there are gud questions with nice explanations On Aug 17, 7:27 pm, saurabh singh wrote: > Kindly suggest some references on forkI know what it is and how it > works.Its just that there are few programs related with recursion that > I have to do using fork.I am

[algogeeks] Re: fork() question

2011-08-14 Thread siva viknesh
thanks a lot guys :) On Aug 15, 12:32 am, SuDhir mIsHra wrote: > 2) > int main() > { > fork(); > fork(); > fork(); > fork() > printf("Hello world!"); > > } > >  a.out─┬─a.out─┬─a.out─┬─a.out───a.out >                                   │       │       └─a.out >                                   │

Re: [algogeeks] Re: fork() question

2011-08-14 Thread SuDhir mIsHra
2) int main() { fork(); fork(); fork(); fork() printf("Hello world!"); } a.out─┬─a.out─┬─a.out─┬─a.out───a.out │ │ └─a.out │ ├─a.out───a.out │ └─a.out

Re: [algogeeks] Re: fork() question

2011-08-14 Thread shady
it is working fine try it on any version of gcc or g++ compiler thread closed * On Sun, Aug 14, 2011 at 11:47 PM, siddharam suresh wrote: > do somebody tried the redirecting the output to file??? > sometime results are unpredictable > Thank you, > Siddharam > > >

Re: [algogeeks] Re: fork() question

2011-08-14 Thread siddharam suresh
do somebody tried the redirecting the output to file??? sometime results are unpredictable Thank you, Siddharam On Sun, Aug 14, 2011 at 11:25 PM, Yasir wrote: > Check out second run of same code: http://ideone.com/TK4qu. This time it > printed only 8 times. > > The reason behind this is that, y

[algogeeks] Re: fork() question

2011-08-14 Thread Yasir
Check out second run of same code: http://ideone.com/TK4qu. This time it printed only 8 times. The reason behind this is that, you are using a web based compiler and it sends back the output as soon as main completes its execution. However forked child are yet to complete. -- You received

Re: [algogeeks] Re: fork() question

2011-08-14 Thread Dipankar Patro
search in group archive, this question has been discussed very deeply On 14 August 2011 23:14, sivaviknesh s wrote: > > http://faq.programmerworld.net/networking/unix-interview-questions-answers.html > > refer 16 th ques in this site .. they ve told 2^n times..so only i asked > whether its compi

[algogeeks] Re: fork() question

2011-08-14 Thread sivaviknesh s
http://faq.programmerworld.net/networking/unix-interview-questions-answers.html refer 16 th ques in this site .. they ve told 2^n times..so only i asked whether its compiler dependent ?? On Sun, Aug 14, 2011 at 11:12 PM, sivaviknesh s wrote: > int main() > { > fork(); > fork(); > fork(); > print

[algogeeks] Re: fork() problem

2010-09-06 Thread Sachin Midha
The answer is 19, but it is compiler dependent, ill explain that at the very end. L1 - Fork(1); L2 - Fork(2) && Fork (3) || Fork (4); L3 - Fork (5); Suppose our initial process was P0. After L1, we have P0 & its child P1. This is pretty clear. At L2, after first fork(), P0 creates P2, P2's work f

[algogeeks] Re: fork() problem

2010-09-05 Thread jayesh
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 wrote: > @Sachin, @Mohit:- > > You are right 19 new processes will get created. Thanks guys. > > #include > #i

[algogeeks] Re: fork() problem

2010-09-05 Thread jayesh
I dont understand, running this code on ideone.com shows create much more than a 50 times On Sep 4, 10:47 pm, PremShankar Kumar wrote: > #include > #include > > using namespace std; > > int Fork() > { > cout<<"\nCREATE \n"; > return fork();} > > int main() > { > Fork(); > Fork() && Fork () |

Re: [algogeeks] Re: fork() problem

2010-09-05 Thread PremShankar Kumar
@Sachin, @Mohit:- You are right 19 new processes will get created. Thanks guys. #include #include using namespace std; int Fork(int i) { //cout< 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

[algogeeks] Re: fork() problem

2010-09-05 Thread sachin
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 " wrot

Re: [algogeeks] Re: fork() problem

2010-09-05 Thread MOHIT ....
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 inpu

Re: [algogeeks] Re: fork() problem

2010-09-04 Thread Aravind
If main process is included then 20... On Sun, Sep 5, 2010 at 12:01 AM, PremShankar Kumar wrote: > @albert:- > Here you go:- > > #include > #include > > using namespace std; > > > int Fork(int i) > { > cout< return fork(); > } > int main() > { > Fork(1); > Fork(2) && Fork (3) || Fork (4); > F

Re: [algogeeks] Re: fork() problem

2010-09-04 Thread PremShankar Kumar
@albert:- Here you go:- #include #include using namespace std; int Fork(int i) { cout< wrote: > yes ..19 is the correct answer. > > p(f1) >/ \ >

Re: [algogeeks] Re: fork() problem

2010-09-04 Thread vikash jain
yes ..19 is the correct answer. p(f1) / \ p1 p

Re: [algogeeks] Re: fork() problem

2010-09-04 Thread albert theboss
@prem: Could u explain please ??? in the end of second line of main how many processes are created??? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Re: fork() problem

2010-09-04 Thread PremShankar Kumar
#include #include using namespace std; int Fork() { cout<<"\nCREATE \n"; return fork(); } int main() { Fork(); Fork() && Fork () || Fork (); Fork (); } Ans:- 19 Regards, Prem On Sat, Sep 4, 2010 at 11:02 PM, Maria wrote: > > Bt then the choices provided are > > > a. 15 > b. 19 > c. 21 > d.

[algogeeks] Re: fork() problem

2010-09-04 Thread Maria
Bt then the choices provided are a. 15 b. 19 c. 21 d. 27 e. 31 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubs