简体   繁体   English

不同进程共享同一个堆

[英]same heap is shared between difference processes

Does a parent process share the same heap with its child process?父进程是否与其子进程共享同一个堆? I find something online: "The heap, code and library regions of the parent are shared by the child. A new stack is allocated to the child and the parent's stack is copied into the child's stack."我在网上找到了一些东西:“父级的堆、代码和库区域由子级共享。一个新的堆栈被分配给子级,父级的堆栈被复制到子级的堆栈中。”

Does this mean same heap is shared between difference processes?这是否意味着不同进程之间共享同一个堆?

"Also there might be a global heap (look at Win32 GlobalAlloc() family functions for example) which is shared between processes, persists for the system runtime and indeed can be used for interprocess communications." “也可能有一个全局堆(例如,查看 Win32 GlobalAlloc() 系列函数),它在进程之间共享,在系统运行时持续存在,并且确实可用于进程间通信。” reference: Is heap memory per-process?参考: 堆 memory 是每个进程吗? (or) Common memory location shared by different processes? (或)不同进程共享的公共 memory 位置?

Does a parent process share the same heap with its child process?父进程是否与其子进程共享同一个堆? I find something online: "The heap, code and library regions of the parent are shared by the child. A new stack is allocated to the child and the parent's stack is copied into the child's stack."我在网上找到了一些东西:“父级的堆、代码和库区域由子级共享。一个新的堆栈被分配给子级,父级的堆栈被复制到子级的堆栈中。”

Does this mean same heap is shared between difference processes?这是否意味着不同进程之间共享同一个堆?

The child process gets a copy of parent heap.子进程获取父堆的副本。 The page frames can be shared between the processes in copy-on-write mode as an optimization.作为一种优化,页框可以在写时复制模式下的进程之间共享。

man fork : man fork

fork() creates a new process by duplicating the calling process. fork() 通过复制调用进程来创建一个新进程。 The new process is referred to as the child process.新进程称为子进程。 The calling process is referred to as the parent process.调用进程称为父进程。

The child process and the parent process run in separate memory spaces.子进程和父进程分别运行在memory空间。 At the time of fork() both memory spaces have the same content.在 fork() 时,两个 memory 空间具有相同的内容。 Memory writes, file mappings (mmap(2)), and unmappings (munmap(2)) performed by one of the processes do not affect the other. Memory 其中一个进程执行的写入、文件映射 (mmap(2)) 和取消映射 (munmap(2)) 不会影响另一个进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM