in Operating System retagged by
992 views
2 votes
2 votes

How is the answer coming out to be 32?

in Operating System retagged by
992 views

3 Answers

4 votes
4 votes

Total no. of child process = 2n-1

                                          = 25-1 = 31

and 1 parent process ..

Total processes = 31 + 1 = 32

by

2 Comments

but parent process is not created na he asked only the  processes that were newly created
5
5
I think by processes created they mean to say processes created on the execution of the whole program which includes parent process also.
0
0
2 votes
2 votes
for each fork call two processes are created , one is parent and other is child

fork() returns pid which can be negative: unsuccessful

it returns +ve pid (process id of child process) to the parent process and pid=0 to the newly created child process.
by

3 Comments

That I know. But the general formula is 2^n -1.  whu isn't answer 31?
0
0

no this formula is used when u have some output getting printed from the output buffer of the process...where at each process creation we have exact copy of child so if n times fork is called then 2^n pocesses are created

by fixing one process (parent) as root , we will have 2^n-1 processes for which output is printed.

example :

for(int i=1; i<=3; i++)

{

pid[i]=fork();

printf("hello");

}

here how many times hello will be printed...ans is 2^3-1 =7

u can refer: http://stackoverflow.com/questions/19106576/how-many-processes-are-created-with-these-fork-statements

At any point, the number of child processes is 2^N-1 and the number of parent processes is since only the first process which started is considered the parent in this scenario.

0
0

WRONG!! 

Hello will be printed 14 times!

https://stackoverflow.com/questions/19106576/how-many-processes-are-created-with-these-fork-statements

See this to get better understanding. GUYS DONT GET CONFUSED!

1
1
0 votes
0 votes
Find total no. Of child is 2^n-1

then 2^5-1=31

And one parent process also add

That's why answer is 31+1=32

Related questions

3 votes
3 votes
1 answer
4