Child processes - Example - Operating System

Q.  A process executes the code,

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

How many child processes are created?

- Published on 26 Aug 15

a. 5
b. 8
c. 7
d. 9

ANSWER: 7
 

    Discussion

  • Nirja Shah   -Posted on 23 Nov 15
    - Let's put some label names for the three lines

    fork (); // Line 1
    fork (); // Line 2
    fork (); // Line 3

    - Line 1 will create one child process

    - Line 2 will create two child processes

    - Line 3 will create four child processes

    - A direct formula can be used to get the number of child processes.

    - When there are n fork statements, there are always 2 n – 1 child processes.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)