什么父进程的东西在Linux中新创建的子进程中共享

Raj*_*har 4 linux

当进程使用子进程创建子进程时fork(),父进程的哪些内容与子进程共享.像地址空间,内存,信号等

注意: - 我已经通过了fork手册.我还需要更多关于它的信息.我也有谷歌它.但我不需要完全了解它.请有人解释我叉子是如何工作的.

suj*_*jin 7

来自W. Richard Stevens 的UNIX高级编程

孩子是父母的副本.例如,子节点获取父节点的数据空间,堆和堆栈的副本.请注意,这是孩子的副本; 父母和孩子不共享这些记忆部分

fork的一个特征是父节点中打开的所有文件描述符都在子节点中重复.

父级还有许多其他属性,这些属性由子级继承:

1. real user ID, real group ID, effective user ID, effective group ID
2. supplementary group IDs
3. process group ID
4. session ID
5. controlling terminal
6. set-user-ID flag and set-group-ID flag
7. current working directory
8. root directory
9. file mode creation mask
10. signal mask and dispositions
11. the close-on-exec flag for any open file descriptors
12. environment
13. attached shared memory segments
14. resource limits
15. Memory mappings
Run Code Online (Sandbox Code Playgroud)

父母和孩子之间的差异是

1. the return value from fork
2. the process IDs are different
3. the two processes have different parent process IDs—the parent process ID of the     child is the parent; the parent process ID of the parent doesn't change
4. the child's values for tms_utime, tms_stime, tms_cutime, and tms_ustime are set to 0
5. file locks set by the parent are not inherited by the child
6. pending alarms are cleared for the child
7. the set of pending signals for the child is set to the empty set
Run Code Online (Sandbox Code Playgroud)


abl*_*igh 2

在我的书中,任何对史蒂文斯的提及通常都是一个很好的参考。然而,史蒂文斯没有做的一件事就是给出 Linux 具体的答案,而且clone当史蒂文斯写他的书时,系统调用还不存在。

鉴于您已经标记了此 Linux,我假设您想要 Linux 特定的答案,您可以通过 找到该答案man clone。这为您提供了可能或可能不与 共享的事物的完整列表fork(),如fork()使用 实现的那样clone()。根据记忆,fork()使用clone()传递标志(即 a )。因此,联机帮助页将准确地告诉您它的作用和不复制的内容。0clone()

这里有一个很好的解释: https://unix.stackexchange.com/questions/87551/which-file-in-kernel-species-fork-vfork-to-use-sys-clone-system-call