How the memory is mapped when fork is used?

前端 未结 3 403
眼角桃花
眼角桃花 2021-01-18 20:03

i am new to \"fork()\",I read everywhere that when a fork() is called an exact copy of current (calling) process is started.Now when I run following code ,there should be tw

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 20:10

    having two different memory locations assigned to their vars and functions.

    Nope; Linux implements virtual memory, meaning that each process has its own complete address space. As a result, after a fork, both processes see the same addresses for their copies of in-memory objects.

    (As an aside: VM also causes code to be shared between the process in physical memory, and all data will only be copied-on-write.)

提交回复
热议问题