How many processes are forked here

后端 未结 4 835
不知归路
不知归路 2020-12-22 13:52

I know that it might come as a stupid question but could anyone help me understand the behavior of the following code snippet

//label 0
int main(){
  fork();         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-22 14:25

    The process tree looks like below. I used following naming convention for processes. prefix parent process name to the corresponding fork label that created it.

                    [0]
              /      |      \
            [01]    [02]    [03]
           /  \       |
        [012] [013] [023]
         /
       [0123]
    

    Like @Mat said, 8 processes are created.

提交回复
热议问题