Access mmap memory from another process

I started playing with mmap. I am trying to create an approximate workspace that will then be extended to a real case.

This is what I want to achieve:

PROCESS 1:

  • mmap file (this is actually a device, but it’s ok to generate an example with a text file)

PROCESS 2: (not torn from process 1, but only an independent process)

  • read memory displayed by process 1
  • change some bits
  • write it to a new file

I read a few examples and documents, but I still have not found how to do this. I am missing:

  • how to handle 2 access to the memory displayed by process 1 without knowing anything about the file that opened?
  • How can I put the contents of mmap in a new file? I assume that I need ftruncate a new file, mmap this file and memcpy the contents of the process 1 memory card to process 2 memory cards (then msync)

Lateral information. I have a message queue open between two processes, so they can share some messages (e.g. address / memory size, ...).

Any clues?

Thanks in advance!

Mix

+4
source share
1 answer

In this answer, you are trying to do this on linux / unix.

how to handle 2 access to the memory displayed by process 1 without knowing anything about the file that opened?

Process 1 passes the MAP_SHARED flag to mmap [1].

You can:

  • A) Share the file descriptor using unix domain sockets [2].
  • B) , , .

2 mmap MAP_SHARED. mmaped Process 1 2. , 1, msync [3]

mmap ? , ftruncate , mmap memcpy 1 2 ( msync)

mmaped ?

[1] http://man7.org/linux/man-pages/man2/mmap.2.html

[2]

[3] http://man7.org/linux/man-pages/man2/msync.2.html

+2

All Articles