Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS: How many process are created by the program?

#include<stdio.h>
#include<unistd.h>

int main()
{
    int i;
    for(i=0;i<4;i++)
        fork();
    return 0;
}

my question:Include the initial parent process, how many processes created by the program?

I think this answer is 1+4=5 , 1 parent process and 4 child process ,am i right?

thanks

like image 687
Steven Chou Avatar asked Nov 27 '22 17:11

Steven Chou


1 Answers

Answer using fork() three times

The answer using fork() four times is: 2 * 2 * 2 * 2 - 1 = 16 - 1 = 15 processes.

like image 165
Jaime Montoya Avatar answered Dec 06 '22 09:12

Jaime Montoya