search
Log In
1 vote
567 views

Consider the following piece of C code:
 

void main( ) {

      fork( );
      fork( ); 
      exit( ); 

} 

How many child processes are created upon execution of this program?

in Operating System 567 views

6 Answers

0 votes
Total child process = 2^n -1  , where n is number of time fork will call

 

2^2-1 =3
0 votes
here fork() fnction is executing twice and n=2.

we the nos of child processes are  (2^n)-1= (2^2)-1=4-1=3
0 votes
Generally when a fork is called for n times then total number of child processes that is generated is 2^(n)-1

In the above problem it is called 2 times so it generates 2^(2)-1 =3 number of child processes will be generated.
0 votes
No of child processes created is 2^n-1.

Here n is the number of times fork is called.
0 votes

Given statements ,

  1. void main( ) {
  2.       fork( );
  3.       fork( );
  4.       exit( );
  5. }

At line #2,

           one child process will be created.

Now we have total 2 processes, 1 child process and another parent,

And the next statement to execute is line#3 in both processes.

 

At line #3


Now both processes(1 parent and 1 child process)  executes line#3 ,  and this will create two child processes.

One created by parent , And another by child (which was earlier created at line #2).


So,

total child processes are 1(line#2) + 2(line#3) → 3 child processes

 

 

General formula for calculating no. of child processes  (2^n) -1  (unless the fork is not called upon any condition)

0 votes
2^2-1 =3

Hence ans : 3

Related questions

0 votes
0 answers
1
115 views
Five batch jobs. $A$ through $E$, arrive at a computer center at almost the same time. They have estimated running times of $10, 6, 2, 4,$ and $8$ minutes. Their (externally determined) priorities are $3, 5, 2, 1,$ and $4,$ respectively, with $5$ being the highest ... the CPU. For $(b)$ through $(d),$ assume that only one job at a time runs, until it finishes. All jobs are completely CPU bound.
asked Oct 25, 2019 in Operating System Lakshman Patel RJIT 115 views
0 votes
1 answer
2
1 vote
1 answer
3
190 views
Measurements of a certain system have shown that the average process runs for a time $T$ before blocking on $I/O$. A process switch requires a time $S$, which is effectively wasted (overhead). For round-robin scheduling with quantum $Q$, give a formula for the CPU efficiency for each of the following: $Q = \infty$ $Q > T$ $S < Q < T $ $Q = S$ $Q\: \text{nearly}\: 0$
asked Oct 25, 2019 in Operating System Lakshman Patel RJIT 190 views
...