简体   繁体   English

在同一内存空间中打开两个程序

[英]Opening two programs in a same memoryspace

Is it possible to launch two completely independent programs into one scope of memory area? 是否可以将两个完全独立的程序启动到一个存储区范围内?

For example, I have skype.exe and opera.exe and I want to launch them on a way that will allows them to share common memory. 例如,我有skype.exeopera.exe ,我想以允许它们共享公用内存的方式启动它们。 Sounds like threading to me. 听起来像是在串扰我。

If they are two independent programs running then you have to ensure that the data is passed in an independent way between them. 如果它们是两个运行的独立程序,则必须确保数据在它们之间以独立的方式传递。 Let's say the two programs are running, the first program compute some data that the second program needs. 假设两个程序正在运行,第一个程序计算第二个程序需要的一些数据。 The simplest thing to do is print the data from the first program into a file with some status at the end of the file (to indicate that it is safe for the other program to start reading it). 最简单的操作是将第一个程序中的数据打印到文件中,文件末尾带有某种状态(以表明其他程序开始读取它是安全的)。 From the other program you have a while loop that checks the status of the last line in that file every period of time. 在另一个程序中,您有一个while循环,该循环每隔一段时间检查该文件中最后一行的状态。

The other option is to use some library like MPI which has protocols for message passing implemented. 另一个选择是使用某些库,例如MPI,该库已实现了用于消息传递的协议。

These are quite some questions at the same time, let me try to dissect: 这些是同时存在的一些问题,让我尝试剖析:

  • It is the definition of a process on a modern OS to have its own virtual address space. 它是现代OS上具有自己的虚拟地址空间的进程的定义。 So running two processes in the same address space can't happen without a modification to the OS to allow exactly that. 因此,如果不修改操作系统以使其完全允许,则无法在同一地址空间中运行两个进程。
  • Even if such a modification were available, it would be a less than perfect idea: Access to memory shared between threads is governed by synchronisation primitives explicitly built into them. 即使可以进行这种修改,也不是一个完美的主意:对线程之间共享的内存的访问由显式内置在线程中的同步原语控制。 There is no such mechanism to manage memory access between two processes, that have not explicitly been designed so 没有这样的机制来管理尚未明确设计的两个进程之间的内存访问
  • Sharing memory if so designed between processes does not at all need them to run in the same virtual address space in their totality: Shared memory segments exist in virtually all modern OS to facilitate exactly that. 如果在进程之间如此设计共享内存,则根本不需要它们全部在同一虚拟地址空间中运行:共享内存段实际上存在于所有现代OS中,以方便地实现这一点。 Again, those processes have to be explicitly designed to use this feature. 同样,必须明确设计这些过程才能使用此功能。

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

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