mmap and shared memory

greg greg at cosc.canterbury.ac.nz
Tue Feb 12 23:58:25 EST 2008


Carl Banks wrote:
> In C you can use the mmap call to request a specific physical location
> in memory (whence I presume two different processes can mmap anonymous
> memory block in the same location)

Um, no, it lets you specify the *virtual* address in the process's
address space at which the object you specify is to be mapped.

As far as I know, the only way two unrelated processes can share
memory via mmap is by mapping a file. An anonymous block is known
only to the process that creates it -- being anonymous, there's
no way for another process to refer to it.

However, if one process is forked from the other, the parent
can mmap an anonymous block and the child will inherit that
mapping.

(I suppose if both processes had sufficient privileges they
could map physical memory out of /dev/mem, but that would be
*really* dangerous!)

--
Greg



More information about the Python-list mailing list