879 views
3 votes
3 votes
What is the output and how many child(what is the code of all other child .what they copied from parent give tree diagram)

t1=0;t2=0;

Fork();

Printf("hi");

t1=Fork();

Printf("hi");

t2=fork();

printf("hi);

fork();

printf("hi);

3 Answers

0 votes
0 votes
30  "Hi"    16 processes (15 child, 1 parent)
0 votes
0 votes
Answer is 64.

stdout is buffered. So, 16 processes with 4 printfs each, produces 64 hi's.

Note: I ran the code myself, it produced 64 hi's.

Related questions

2 votes
2 votes
3 answers
2
Philosophical_Virus asked Dec 10, 2023
768 views
Int main (){fork();printf("a");fork();printf("b");return 0;}How many distinct outputs are possible of above code? And also give outputs
3 votes
3 votes
1 answer
3
24aaaa23 asked Oct 1, 2023
723 views
Consider the following code segment :int main (void) { for (int i=2; i<=5; i++) { fork( ); }printf (“GOCLASSES”);How many times “GOCLASSES” is printed by the ab...
0 votes
0 votes
0 answers
4