What happens when fork is called 3 times?

Trang Esther

New member
What happens when fork is called 3 times?
Answer
If the parent and child keep executing the same code (i.e. they don’t check the return value of fork() , or their own process ID, and branch to different code paths based on it), then each subsequent fork will double the number of processes. So, yes, after three forks, you will end up with 2³ = 8 processes in total.
 

Tìm kiếm

Back
Top