25 views

How many total processes will be spawned after executing following program?

int main()

{

fork() || fork() && fork() ;

}

I am getting 5...please someone verify..

My attempt—

Each leaf node corresponds to a process

I firstly performed && then | | and applied some greedy rules as—

In A&&B if A=0 then B will not be evaluated and results in 0

In A||B if A=1 then B will not be evaluated and results 1.

edited | 25 views
0
0
I do according to precedence of operators ..

==> fork() || (fork()&&fork())
0

0
0

why you first executed && ?

&& is having higher precedence  and fork() || (fork() && fork()) will execute left to right and leftmost fork will execute first.

similarly while executing a || (b * c), a is read first but then total completion of (b*c) is executed first then result of or is executed. (ignoring short-circuiting)

0
We will see associativity, if operators are of same precedence..

Here precedence are different so first && then ||

Right?
0
create a tree of the same you will find && at the bottom and parse the tree from left to right, you will understand how leftmost fork is executed first.
0

similarly while executing a || (b * c), a is read first but then total completion of (b*c) is executed first then result of or is executed. (ignoring short-circuiting)

a is true then b*c never executed. Short circuit rule can't ignorable.

0

i wrote (ignoring short circuiting) because there is no guarantee of  b*c being executed, i was trying to explain him that a will execute first, ofcourse in every question we will consider short circuiting.

0
Ok........