Awesome q2a theme
0 votes

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 (388 points)
edited by | 25 views
show your solution
I do according to precedence of operators ..

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

 yes i understand but please comment your solution.

Sir, i edited question and added my attept..(image added)

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) 

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

Here precedence are different so first && then ||

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.

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.


 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.


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
Top Users 2020 Aug 10 - 16
  1. Arkaprava

    40 Points

  2. jayeshasawa001

    15 Points

  3. Nilabja Sarkar

    8 Points

  4. siddharths067

    4 Points

  5. 404 found

    3 Points

  6. shashankrustagi2021

    2 Points

  7. Ashutosh777

    2 Points

  8. Mellophi

    2 Points

  9. sparshgarg

    1 Points

  10. sonam13

    1 Points

Weekly Top User (excluding moderators) will get free access to GATE Overflow Test Series for GATE 2021
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users Aug 2020
  1. Mellophi

    152 Points

  2. Ashutosh777

    78 Points

  3. anurag sharma

    49 Points

  4. Arkaprava

    40 Points

  5. jayeshasawa001

    20 Points

  6. Kushagra गुप्ता

    15 Points

  7. Shaik Masthan

    13 Points

  8. srestha

    13 Points

  9. shashankrustagi2021

    12 Points

  10. munishchaturvedi

    10 Points

7,746 questions
1,845 answers
95,103 users