1,061 views
if(fork()||fork()) {
fork();
fork();
}
printf("ABC")

HOW MANY TIMES ABC CALLED?

I'm also getting 9
edited

YEPP IT'S 9  .

@ Shaik Masthan @Magma

PLEASE ANYONE EXPLAIN IT WITH THE TREE METHOD

16?

Basics:-

The || operator, if First operand gives true then Second operand doesn't evaluate

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

One thing tell me, how many number of child and parent process created here?

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()