会发生什么当我打电话在Unix中fork()的? [英] What Happens When I Call fork() in Unix?

查看:101
本文介绍了会发生什么当我打电话在Unix中fork()的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看这件事,但我挣扎了一下,了解了父进程和子进程后我叫叉()之间的关系。

他们是否完全独立的过程,只能通过ID /父ID相关联?或者,它们共享内存?比如'code'的每一个过程的部分 - 是的复制的使每一个过程都有它自己相同的副本,或者是,共享在某些方面,这样只存在一个? / p>

我希望是有道理的。

在充分披露的名称,这是'功课有关的;而从书中没有一个直接的问题,我有一种感觉它主要是学术,并在实践中,我可能不需要知道的。


解决方案

由于它出现在处理中,整个存储器被复制

在现实中,它使用写入时复制的系统。第一次任一过程的变化后叉它的内存(),一个独立的副本作出修改后的页面(通常是4kB的)的。

一般的处理的code段不被修改,在这种情况下,它仍共享

I've tried to look this up, but I'm struggling a bit to understand the relation between the Parent Process and the Child Process immediately after I call fork().

Are they completely separate processes, only associated by the id/parent id? Or do they share memory? For example the 'code' section of each process - is that duplicated so that each process has it's own identical copy, or is that 'shared' in some way so that only one exists?

I hope that makes sense.

In the name of full disclosure this is 'homework related'; while not a direct question from the book, I have a feeling it's mostly academic and, in practice, I probably don't need to know.

解决方案

As it appears to the process, the entire memory is duplicated.

In reality, it uses "copy on write" system. The first time either process changes its memory after fork(), a separate copy is made of the modified page (usually 4kB).

Usually the code segment of a process is not modified, in which case it remains shared.

这篇关于会发生什么当我打电话在Unix中fork()的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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