Fork - same memory addresses?

前端 未结 5 787
青春惊慌失措
青春惊慌失措 2020-12-01 11:18

This is about C in Linux.

I have fork() in main() where I create 2 child processes. Then, in both child process a run the function ab

5条回答
  •  抹茶落季
    2020-12-01 11:39

    If you stop to think for a minute, it would be impossible for fork to give variables separate addresses in the parent and child process. You could already have stored the addresses anywhere in memory, or hashed them, or saved them out to a file, or anything, and then anything in the child that depended on these addresses being valid would horribly break. In fact fork does and must create a child process in which the virtual address space is identical to the virtual address space of the parent.

提交回复
热议问题