Is there a way to force a process to share address space from another process?

851 Views Asked by At

This is a purely theoretical question. As far as I'm concerned each process have different addressing space and each thread inside one process share the same memory space?

Is there a way, especially in some UNIX system to change that behavior. To be more clear, to make two processes share the same address space? Or to make two threads from the same process to have different address space?

2

There are 2 best solutions below

0
mevets On BEST ANSWER

Yes. Google gvisor or rump for examples of how to do this. Short story is you start with a Mother process, which forks() to create new children. These children are managed by ptrace() which isolates them from the kernel. The mother process then manipulates the address space(s) of the children as it sees fit; making them identical is one option.

There is usually a bit of a bootstrapping trick involved, so when a child calls fork(), the Mother forks and execs a known binary (re: aspace layout), then proceeds to clone the original fork()ers aspace into the new one.

0
Artur Barsegyan On

I think you should probably read this.

Shared memory — is memory that may be simultaneously accessed by multiple programs with an intent to provide communication among them or avoid redundant copies. Shared memory is an efficient means of passing data between programs.