Awesome q2a theme
0 votes
13 views

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

int main()

{

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

}

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

But Here it is given 7


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.

in Operating System by (386 points)
edited by | 13 views
0
show your solution
0
I do according to precedence of operators ..

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

 yes i understand but please comment your solution.

0
Sir, i edited question and added my attept..(image added)
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........

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users Jan 2020
  1. shashin

    1163 Points

  2. Vimal Patel

    307 Points

  3. Deepakk Poonia (Dee)

    305 Points

  4. Debapaul

    237 Points

  5. Satbir

    192 Points

  6. SuvasishDutta

    137 Points

  7. Pratyush Priyam Kuan

    118 Points

  8. tp21

    108 Points

  9. DukeThunders

    96 Points

  10. pranay562

    95 Points

Monthly Top User and those within 60% of his/her points will get a share of monthly revenue of GO subject to a minimum payout of Rs. 500. Current monthly budget for Top Users is Rs. 75.
2,989 questions
1,509 answers
8,936 comments
89,814 users