OpenBSD manual page server

Manual Page Search Parameters

SHM_OPEN(3) Library Functions Manual SHM_OPEN(3)

shm_open, shm_unlink, shm_mkstempcreate and destroy shared memory objects

#include <sys/mman.h>

shm_open(const char *path, int flags, mode_t mode);

shm_unlink(const char *path);

shm_mkstemp(char *template);

The () function opens a shared memory object and returns a file descriptor suitable for use with mmap(2). The flags argument has the same meaning as provided to open(2) and must include at least O_RDONLY or O_RDWR and may also include a combination of O_CREAT, O_EXCL, O_CLOEXEC, O_NOFOLLOW, or O_TRUNC. This implementation forces the mode to be 0600 or 0400, and prohibits sharing between different UIDs.

If a temporary shared memory object is desired, the () function should be preferred as it avoids several possible security holes that tend to appear in programs trying to create their own unique temporary names. The template argument is a string with at least six trailing Xs as described in mkstemp(3).

shm_open() and shm_mkstemp() return a file descriptor on successful completion. They may fail for any of the reasons listed in open(2).


shm_open() and shm_unlink() appear in IEEE Std 1003.1-2001 (“POSIX.1”). Using O_CLOEXEC or O_NOFOLLOW with shm_open() is an extension to that standard. This implementation deviates from the standard by permitting less sharing.

shm_mkstemp() is an extension.

The shm_open(), shm_unlink(), and shm_mkstemp() functions have been available since OpenBSD 5.4.

Ted Unangst <‍>.

May 5, 2015 OpenBSD-current