188 views

1 Answer

1 votes
1 votes

Let's consider following code:

   fork(); // Consider as A
   fork() && fork() || fork(); // Consider B, C and D respectively 
   fork(); // Consider E

and, 


The logical operator && has more precedence than ||, and have left to right associativity. 

In case of AND (&&), after evaluation of left operand, right operand will be evaluated only if left operand evaluates to non-zero. In case of OR (||), after evaluation of left operand, right operand will be evaluated only if left operand evaluates to zero.

And, in fork(), parent process returns non-zero whereas a child process returns zero.

So, with above considerations 

At level 5, we will have 20 processes running.

Therefore, 

printf("Hi");

will be executed 20 times.

Related questions

1 votes
1 votes
1 answer
1