如何写入时复制工作叉EXEC? [英] How does copy-on-write work in fork-exec?

查看:130
本文介绍了如何写入时复制工作叉EXEC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个过程是个子进程,并调用执行exec()中的子进程。
与写入时复制后,父进程和子进程共享的内存。

当子进程调用执行exec()加载另一个进程,将Linux的母体存储复制到新的内存和孩子也加载另一个进程这一新的内存?如果是这样,这是否意味着用做叉Exec时写入时复制没有得到数据分叉过程?


解决方案

  

通过写入时复制后,父进程和子进程共享的内存。


是阅读,也没有进行写入。对于派生的子进程会创建一个新的地址空间,不仅是填充它,直到把它写在孩子发生。

如果叉()后面紧跟着执行exec(),为孩子创造的地址空间,而叉() ING通常不使用,但是由一个新的,即该过程的exec()编辑。

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?

解决方案

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.

这篇关于如何写入时复制工作叉EXEC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆