c++ - Access mmap memory from another process -
i've started playing mmap. i'm trying create example workspace extended real case.
this want achieve:
process 1:
- mmap file (actually device, it's okay generate example text file)
process 2: (not foked process 1; independent process)
- read memory mapped process 1
- change bits
- write new file
i've read several examples , documentations, still didn't find how achieve this. i'm missing is:
- how can process 2 access memory mapped process 1, without knowing opened file?
- how can put mmap content in new file? suppose have ftruncate new file, mmap file , memcpy content of process 1 memory map process 2 memory map (then msync)
side info, have message queue opened between 2 processes, can share messages if needed (ex. memory address/size, ...).
any hints?
thanks in advance!
mix
this answer considers trying stuff on linux/unix.
how can process 2 access memory mapped process 1, without knowing opened file?
process 1 passes mmap[1] flag map_shared.
you can:
- a) share file descriptor using unix domain sockets[2].
- b) send name of file using queues mentioned @ end of message.
process 2 opens mmap flag map_shared. modifications mmaped memory in process 1 visible process 2. if need fine control of when changes process 1 shown process 2 should control msync[3]
how can put mmap content in new file? suppose have ftruncate new file, mmap file , memcpy content of process 1 memory map process 2 memory map (then msync)
why don't write mmaped memory regular memory write?
[1]http://man7.org/linux/man-pages/man2/mmap.2.html
[2]portable way pass file descriptor between different processes
Comments
Post a Comment