4 votes 4 votes if(fork()||fork()) { fork(); fork(); } printf("ABC") HOW MANY TIMES ABC CALLED? Deepanshu asked Sep 13, 2018 Deepanshu 1.6k views answer comment Share Follow See all 7 Comments See all 7 7 Comments reply Show 4 previous comments Magma commented Sep 13, 2018 reply Follow Share I'm also getting 9 0 votes 0 votes Deepanshu commented Sep 13, 2018 i edited by Deepanshu Sep 13, 2018 reply Follow Share YEPP IT'S 9 . @ Shaik Masthan @Magma PLEASE ANYONE EXPLAIN IT WITH THE TREE METHOD 0 votes 0 votes neeti commented Sep 13, 2018 reply Follow Share 16? 0 votes 0 votes Please log in or register to add a comment.
Best answer 8 votes 8 votes Basics:- The || operator, if First operand gives true then Second operand doesn't evaluate For clear image https://drive.google.com/open?id=1S538Oa9z0Bm4YtBZeJHxARH2pqPxtLLz you can also check following links for better understanding variations on fork() system call https://gateoverflow.in/232839/fork-system-call https://gateoverflow.in/231896/fork-system-call Shaik Masthan answered Sep 13, 2018 selected Sep 13, 2018 by Deepanshu Shaik Masthan comment Share Follow See all 15 Comments See all 15 15 Comments reply Show 12 previous comments srestha commented Sep 15, 2018 reply Follow Share One thing tell me, how many number of child and parent process created here? 0 votes 0 votes Shaik Masthan commented Sep 15, 2018 reply Follow Share here means, LOGICAL OR or LOGICAL AND , in which question? So, 1st fork() executed , 2 process created 1) Parent process(fork1() !=0) and 2) child process (fork1()=0) i agree. Now, when 2nd fork2() calls- only fork1()!=0 will be executed,So,again 2 process will be created [Here fork1()=0 only be executed, iff there is some else part in program, but that is not the case here] it is wrong. fork1()!=0 ===> directly enter into IF BLOCK, due to it is logical OR. fork1() = 0 ===> it will be executed on 2nd fork() Please revise your basics on LOGICAL OR and LOGICAL AND operators. https://www.geeksforgeeks.org/operators-in-c-set-2-relational-and-logical-operators/ 1 votes 1 votes srestha commented Sep 15, 2018 reply Follow Share See I have applied this logic only The ‘||’ operator returns true when one (or both) of the conditions in consideration is satisfied Have u understand properly? 0 votes 0 votes Please log in or register to add a comment.