Fork : number of processes created [closed]

2019-09-30 07:54发布

问题:

main(){
    int i; 
    for(i=0;i<4;i++) 
    fork(); 
    while(1);
}

Is the above graph, the output of the code?

回答1:

No, that's not quite correct though it's close. Think about the properties of all those processes down the left hand side. p0 creates four children, p1 creates three, and so on.

Since this is undoubtedly something you're supposed to nut out yourself, I won't make it any clearer, that should be more than enough to work it out. You may want to actually run the code and count how many processes are created. It's only slightly more than the fifteen you have.



标签: c fork