694 views
2 votes
2 votes

2 Answers

4 votes
4 votes

                                       

               answer is 4.    dont count c1 c2 c3 c4..the childrens are at t1=0,t2 = 0,at t3 =0 for both t2 != 0 and t2 = 0. so total 4     

edited by
0 votes
0 votes

first fork() creates one new  process , so total processes at this point are 2 (1 parent and 1 child)

the process with value 0 enters inside IF. at second fork processes becomes 2.

thsese two processes executes third fork, now the total new processes are 4 (excluding parent)

t3 initialised with -1, but when fork executed its value get overwrite .. it does not have any effect

Related questions

2 votes
2 votes
1 answer
1
hem chandra joshi asked Aug 20, 2017
554 views
when fork is execute the child process has same virtual address space or physical address space ?when we print address of a variable in c ..what is it :->virtual address ...
3 votes
3 votes
2 answers
2
iarnav asked Oct 18, 2018
1,875 views
A process executes the following segment of code :for(i = 1; i <= n; i++) fork (); fork ();The number of new processes created is
1 votes
1 votes
1 answer
3
2 votes
2 votes
2 answers
4
set2018 asked Jul 7, 2017
11,435 views
How many times "hello" gets printed?main() { fork(); fork(); printf("hello"); }