[LCP] creating a file descriptor entry for a piece of memory

Mark Farnell mark.farnell at gmail.com
Wed Nov 5 10:18:53 EST 2008


mmap maps a file to the memory space and the anoynomous mode of mmap
allows allocation of a piece of memory to an address space, then share
this address space to child processes via fork.

That's great.  However are there any ways to allocate a piece of
memory and assign it to a file ID (no files actually created on HD or
in /dev), then I can mmap that file ID as many times as I like?

The trouble of shm_create is that it creates an entry on the file
system and therefore if I run multiple programs concurrently (which
calls shm_create with the same hard-coded name) I will be in trouble.

That memory should be freed if the process quits by any means.

Can this be done?

Thanks!

Mark



More information about the linuxCprogramming mailing list