No need for additional system calls ( by your process ), you just access it like regular memory. When you re done with the file, just call munmap
.
Return Value
On success, mmap()
returns a pointer to the mapped area.
On error, the value MAP_FAILED
(that
is, (void *) -1) is returned, and
errno is set appropriately. On
success, munmap()
returns 0, on
failure -1, and errno
is set (probably
to EINVAL
).
See the man page here for details.
Edit For clarification:
I m saying that the function maps the file into the calling process s memory space and returns a pointer to the beginning of the memory block.
For example, if you have two different processes map the same file with the MAP_SHARED
flag then each process will be accessing the same physical memory, but that memory may be mapped at a different location in each process s virtual memory space, i.e. the pointers returned by mmap in each process s virtual memory space may not be equal.
This brings up the point that if you for instance need to store pointers inside the shared memory block those pointers would only be useful if they were stored as offsets relative to the beginning of the block / file and they would only be able to usefully point to locations internal to the block / file.