How does copy-on-write work in fork-exec? [closed]

帅比萌擦擦* 提交于 2019-12-02 19:36:00

问题


A process forks a child process, and calls exec() in the child process. With copy-on-write, after fork the parent process and child process share the memory.

When the child process calls exec() to load another process, will Linux copy the parent memory to the new memory and the child loads another process also to this new memory? If so, does that mean the process forked with copy-on-write got no data when doing fork-exec?


回答1:


With copy-on-write, after fork the parent process and child process share the memory.

Yes for reading and no for writing. A new address space is created for the forked child process, only it is not populated until a write to it occurs by the child.

If fork() is immediately followed by exec(), the address space created for the child while fork()ing typically isn't used but is replaced by a new one, namely the one created for the process exec ()ed.



来源:https://stackoverflow.com/questions/31892692/how-does-copy-on-write-work-in-fork-exec

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