About fork system call and global variables

前端 未结 5 1542
遥遥无期
遥遥无期 2021-01-15 04:57

I have this program in C++ that forks two new processes:

#include 
#include 
#include 
#include 

        
5条回答
  •  隐瞒了意图╮
    2021-01-15 05:50

    yes what you have thought is right but in order to save some memory, internally the pages are shared between the parent and the child till the child executes exec system call or modifies any of the variables or the data structures.since many pages are shared between parent and child.....if the page is modified by child,then that page will copied into separate memory area and will be assigned to the child.if it is modified by parent,then that page will be copied to separate memory area and assigned to the parent

提交回复
热议问题