why does this fork() out put produce 8 instead of 5?

后端 未结 3 800
不思量自难忘°
不思量自难忘° 2020-12-22 14:01

So I have to find the output of this code which is using the fork() method. I thought the output was 5 \"hello\" s but instead I got 8. Why is that? This is the

3条回答
  •  囚心锁ツ
    2020-12-22 14:22

    You create process #1. Before printing anything, process #1 calls fork() and generates a clone that we will call process #2. Both processes #1 and #2 call fork() again, cloning into processes #3 and #4. Now you have 4 processes and each one of them will print hello twice. How many hello are printed?

提交回复
热议问题