mmap and shared memory

Ryan Smith-Roberts lab.net at gmail.com
Fri Feb 15 15:17:54 EST 2008


On Feb 11, 3:41 pm, Matias Surdi <matiassu... at gmail.com> wrote:
> Suppose I've a process P1, which generates itself a lot of data , for
> example 2Mb.
> Then, I've a process P2 which must access P1 shared memory and,
> probably, modify this data.
> To accomplish this, I've been digging around python's mmap module, but I
> can't figure how to use it without files.
>
> Could anybody explain me how could this be accomplished? An example will
> be very appreciated. Thanks a lot for your help.

A non-portable solution, for modern Linux systems, is to create and
mmap a file in the /dev/shm directory.  This is a more "unix-y"
solution than the SysV SHM interface mentioned elsewhere in the
thread, since it gives you files you can cat, ls, chown, etc.  Files
created in this directory may hit swap, but don't consume normal disk
space.



More information about the Python-list mailing list