if(fork()||fork()) { fork(); fork(); } printf("ABC")
HOW MANY TIMES ABC CALLED?
YEPP IT'S 9 . @ Shaik Masthan @Magma
PLEASE ANYONE EXPLAIN IT WITH THE TREE METHOD
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
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/
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?