当前位置 : 主页 > 手机开发 > harmonyos >

fork()的一些细节

来源:互联网 收集:自由互联 发布时间:2023-10-08
1、哪些段会被复制 The child gets a copy of the parent's data space, heap, and stack. Note that this is a copy for the child; the parent and the child do not share these portions of memory. The parent and the childshare the text segm


1、哪些段会被复制

The child gets a copy of the parent's data space, heap, and stack. Note that this is a copy for the child; the parent and the child do not share these portions of memory. The parent and the childshare the text segment.(APUE-2e)

2、写时复制技术(COW)


Current implementations don't perform a complete copy of the parent's data, stack, and heap, since a fork is often followed by an exec. Instead, a technique called copy-on-write (COW) is used. These regions are shared by the parent and the child and have their protection changed by the kernel to read-only. If either process tries to modify these regions, the kernel then makes a copy of that piece of memory only, typically a "page" in a virtual memory system.(APUE-2e)


Under Linux, fork() is implemented using copy-on-write pages, so the only penalty that it incurs is the time and memory required to duplicate the parent's page tables, and to create a unique task structure for the child.(man page)

网友评论