I am writing a set of programs on Linux that use shared memory. Currently I call shm_open()
with a predetermined name for the shared memory. This works fine as I currently only have one set of processes running. If I want to have multiple, independent, set running I will need to have a unique filename per set.
Ideally I’m looking for something like mkstemp()
or mkostemp()
, but that works like shm_open()
.
If that’s not something that exists, the two potential options I see are:
- Generate a “unique” filename, potentially based on the executable name and the process ID and use that in the call to
shm_open()
. Is there a way to get this to fail if the shared memory “file” already exists? - Use
mkostemp()
and thenmmap()
that file. Is there any real drawback to doing this? On Linux at leastshm_open()
seems to not have a physical backing file. Is it such a big deal to have on?