What happens to address's, values, and pointers after a fork()

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 07:34:32

The child process has a copy of the parent address space. In modern systems addresses are virtualized, so that any particular pointer address in one process can map to a different physical address in another process.

What happens if I change a variable in the child? Will it change in both parent and child?

The child has its own copy of the variable, so changing a variable in the child will not affect the value of the variable in the parent.

If not, how am I able to change the value in that address while the addres is the same for both parent and child.

This is due to the same address in both processes mapping to different physical addresses.

The address is the same, but doesn't refer to the same memory. Each process has its own address space. This is accomplished on modern systems by virtual memory - on older systems it would be accomplished by segment-base addressing or simply swapping (unloading one process and loading the other one in the same region of memory).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!