I have checked various unix specs and I am puzzled about how to share
memory between two processes using mmap().
AFAIK MAP_ANONYMOUS + MAP_PRIVATE would map /dev/zero (in linux man
pages don't mention /dev/zero) so the process can get some private
zero-initialised free memory, correct?
Then what would MAP_ANONYMOUS + MAP_SHARED do? If Linux specifies no
particular file for MAP_ANONYMOUS where would the shared mapping be
found by another process? Perhaps these two flags don't get used
together?
Thanks,
Bahadir
Before MAP_ANONYMOUS existed, the same effect could be accomplished on
'some operating system' (notably, Solaris) by mmap'ing /dev/zero.
> Then what would MAP_ANONYMOUS + MAP_SHARED do?
Create a memory region shared among all processes created by the
process who mmap'ed it and all processes created by these processes
and ...
> If Linux specifies no particular file for MAP_ANONYMOUS where would
> the shared mapping be found by another process?
Not at all. To share memory among unrelated processing using mmap, one
would either use shm_open or mmap real files.
So in summary you mean an area mapped with MAP_ANON + MAP_SHARED would
be shared among the descendants of the process. That makes sense since
only the descendants would know how to access the area.
> Not at all. To share memory among unrelated processing using mmap, one
> would either use shm_open or mmap real files.
I see that now.
Thanks,
Bahadir