3 ms·
I've programmed with POSIX shared memory, and yes, that's the general idea. A very important caveat is that the POSIX shared memory namespace is shared among a
by agwa 12y ago
I've programmed with POSIX shared memory, and yes, that's the general idea.
A very important caveat is that the POSIX shared memory namespace is shared among all processes, so you need to wrap shm_open with a mkstemp()-style algorithm that generates a random name, opens with O_EXCL, and tries again if it fails. Unfortunately it's very easy to mess that up and introduce a security vulnerability.
- hawski 12y agoIt would be also prefferable to unlink just after /open/ call. Wouldn't mkstemp("/dev/shm/tmp-XXXXXX") be enough. As strace tells /shm_open/ is just a wrapper for /open/ with /dev/shm/ prefix.
- agwa 12y agoOn Linux, shm_open is implemented with /dev/shm, but that's not the case on other platforms.