shm_open(3P4)
NAME
shm_open − open a memory object
SYNOPSIS
#include <sys/mman.h>
int shm_open(name, oflag, mode)
char ∗name;
int oflag;
mode_t mode;
DESCRIPTION
The shm_open function attaches a file descriptor to a memory object. The file descriptor is used by other functions to refer to the memory object. The name argument points to a null-terminated string naming a memory object. name must consist of less than {NAME_MAX} characters from the portable file name character set. Slash (/) characters are not allowed in name. The current working directory does not affect the interpretation of name. Processes calling shm_open with the same value of name will refer to the same memory object.
If successful, shm_open returns a file descriptor for the memory object that is the lowest file descriptor not currently open for that process. The FD_CLOEXEC file descriptor flag is set for the new file descriptor.
The file status flags and file access modes of the open file description will be set according to the value of oflag. The oflag argument is constructed from the bitwise inclusive OR of zero or more of the following flags defined in the header <fcntl.h>
O_RDONLY
Open for read access only.
O_RDWR
Open for read or write access.
O_CREAT
If the memory object exists, this flag has no effect, except as noted under O_EXCL below. Otherwise the memory object is created; the memory object’s user ID will be set to the effective user ID of the process; the memory object’s group ID will be set to the effective group ID of the process. The memory object’s permission bits will be set to the value of the mode argument except those set in the file creation mode mask of the process. When bits in mode other than the file permission bits are set, they are ignored.
O_EXCL
If O_EXCL and O_CREAT are set, shm_open will fail if the memory object exists. If O_EXCL is set and O_CREAT is not set, O_EXCL is ignored.
O_TRUNC
The implementation does not support this flag.
When a memory object is created, the state of the memory object, including all data associated with the memory object, will persist until the memory object is unlinked via shm_unlink(3P4) and all references to the memory object are unmapped.
RETURN VALUE
Upon successful completion, the shm_open function will return a nonnegative integer representing the lowest numbered unused file descriptor. Otherwise, it will return -1 and will set errno to indicate the error. Possible errors include:
[EACCES] The memory object exists and the permissions specified by oflag are denied.
[EEXIST] O_CREAT and O_EXCL are set and the named memory object already exists.
[EINTR] The shm_open operation was interrupted by a signal.
[EMFILE] Too many file descriptors are currently in use by this process.
[ENAMETOOLONG] The length of the name argument exceeds {NAME_MAX}
[ENFILE] Too many memory objects are currently open in the system.
[ENOENT] O_CREAT is not set and the named memory object does not exist, or O_CREAT is set and name points to an empty string.
[ENOSPC] There is insufficient space for the creation of the new memory object.
[ENOTSUP] O_TRUNC was specified and is not supported.
FILES
/usr/lib/libposix4.a
SEE ALSO
mmap(3P4), munmap(3P4), shm_unlink(3P4), "CX/UX Programmer’s Guide"
BUGS
O_TRUNC is not supported for shm_open
WARNING
The interface to shm_open is based on IEEE Draft Standard P1003.4/D12. This is an unapproved draft, subject to change. Use of information contained in this unapproved draft is at your own risk. This interface will change to reflect any changes made by future drafts of POSIX 1003.4.
CX/UX Programmer’s Reference Manual