shm_open(2) shm_open(2)
NAME [Toc] [Back]
shm_open - create/open a shared memory object
SYNOPSIS [Toc] [Back]
#include <sys/mman.h>
int shm_open(const char *name, int oflag, mode_t mode);
DESCRIPTION [Toc] [Back]
The shm_open() system call establishes a connection between a shared
memory object and a file descriptor. It creates an open file
description that corresponds to the shared memory object and returns a
file descriptor that refers to that open file description. This file
descriptor (which is the lowest numbered file descriptor not currently
open for that process) is used by other functions to refer to that
shared memory object.
The name argument points to the shared memory object name, and must
conform to the general construction rules for a pathname.
The oflag argument is the bitwise inclusive OR of the flags listed
under Read-Write Flags and General Flags (these flags are defined in
the header file <fcntl.h>).
The new file descriptor has the FD_CLOEXEC flag set, and consequently
does not remain open across exec*() system calls.
Read-Write Flags [Toc] [Back]
The value of oflag must be composed by taking the inclusive OR of
exactly one of the following flags:
O_RDONLY Open for read access only.
O_RDWR Open for read and write access.
General Flags [Toc] [Back]
Any combination of the following flags may also be used in setting the
value of oflag.
O_CREAT If the shared memory object exists, this flag will
have no effect, except as noted under O_EXCL
below. Otherwise the shared memory object is
created; the shared memory object's user ID is set
to the effective user ID of the process; the
shared memory object's group ID is set to the
effective group ID of the process. The shared
memory object's permission bits is set to the
value of the mode argument except those set in the
file mode creation mask of the process. The new
shared memory object will have a size of zero.
Hewlett-Packard Company - 1 - HP-UX 11i Version 2: August 2003
shm_open(2) shm_open(2)
O_EXCL If O_EXCL and O_CREAT are set in oflag and the
named shared memory object exists, shm_open() will
fail. The O_EXCL flag is ignored if O_CREAT is
not set in oflag.
O_TRUNC If the shared memory object exists, and it is
successfully opened for reading and writing
(O_RDWR set in oflag), the object will be
truncated to zero length. The mode and owner
shall remain unchanged by this function call.
RETURN VALUE [Toc] [Back]
shm_open() returns the following values:
n Successful completion. n is the lowest numbered unused file
descriptor for the process.
-1 Failure. errno is set to indicate the error.
ERRORS [Toc] [Back]
If shm_open() fails, errno is set to one of the following values:
[EACCES] The shared memory object exists and the
permissions specified by oflag are denied, or the
shared memory object does not exist and permission
to create the it is denied, or O_TRUNC is
specified and write permission is denied.
[EEXIST] The O_CREAT and O_EXCL are set in oflag and the
named shared 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 string exceeds PATH_MAX, or
the length of a (pathname) component of the name
string exceeds NAME_MAX while _POSIX_NO_TRUNC is
in effect.
[ENFILE] Too many shared memory objects are currently open
in the system.
[ENOENT] The O_CREAT flag is not set in oflag and the named
shared memory object does not exist.
[ENOSPC] There are insufficient resources for the creation
of the new shared memory object.
Hewlett-Packard Company - 2 - HP-UX 11i Version 2: August 2003
shm_open(2) shm_open(2)
[ENOSYS] shm_open() is not supported by the implementation.
SEE ALSO [Toc] [Back]
shm_unlink(2), close(2), mmap(2), munmap(2).
STANDARDS CONFORMANCE [Toc] [Back]
shm_open() in librt: POSIX 1003.1b
Hewlett-Packard Company - 3 - HP-UX 11i Version 2: August 2003 [ Back ] |