为什么两个相同文件的Linux进程不能共享文本段? [英] Why 2 linux processes of same file cannot share text segment?

查看:73
本文介绍了为什么两个相同文件的Linux进程不能共享文本段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在经历linux进程,但我有以下疑问.

I am going through linux processes and I got the following doubt.

如果我从不同的外壳程序执行两次相同的程序,将创建2个进程.我一直觉得文本段将由这两个进程共享.但是一些互联网页面建议不要在进程之间共享文本段.任何人都可以让我知道为什么不能在不同进程之间共享它吗?

if I execute the same program twice from different shells, 2 processes will be created. I always felt that the text segment will be shared by those 2 processes. But some internet pages suggested that the text segment won't be shared between the processes. Can any one please let me know why it can't be shared between different processes?

推荐答案

在现代OS(如Linux和Windows进程)中,根据定义,它们都被围在自己的沙箱中.有一些共享库(so/dll)已由OS进行了重复数据删除,但它们仅共享代码,没有任何存储内存.当某个进程尝试访问其自身进程空间之外的内存时,CPU的MMU(内存管理单元)部分将生成一个硬信号,如果未明确捕获或处理该硬信号,该信号将终止该进程.在Linux中,这称为分段错误"或segfault,在Windows中,这称为访问冲突".

In modern OSes like Linux and Windows processes are all walled down into their own sandbox by definition. There are shared libraries (so/dll) that are deduplicated by the OS, but they only share the code, no storage memory whatsoever. When a process tries to access memory outside its own process space, the MMU (Memory Management Unit) part of the CPU will generate a hard signal, which will terminate the process if not caught or handled explicitly. In Linux this is called a 'segmentation fault' or segfault, in Windows it's an 'access violation'.

要建立进程间通信(IPC),程序必须通过同步对象和方法(例如匿名/命名管道,内存映射文件,信号,信号量以及更多取决于OS)主动启动此操作.

To establish inter-process communication (IPC) a program has to actively initiate this, through synchronization objects and methods, like anonymous/named pipes, memory mapped files, signals, semaphores and a whole lot more depending on the OS.

这篇关于为什么两个相同文件的Linux进程不能共享文本段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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