Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

shm_open(2) [hpux man page]

shm_open(2)							System Calls Manual						       shm_open(2)

NAME
shm_open - create/open a shared memory object SYNOPSIS
DESCRIPTION
The 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 mem- ory 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 and (these flags are defined in the header file The new file descriptor has the flag set, and consequently does not remain open across system calls. Read-Write Flags The value of oflag must be composed by taking the inclusive OR of exactly one of the following flags: Open for read access only. Open for read and write access. General Flags Any combination of the following flags may also be used in setting the value of oflag. If the shared memory object exists, this flag will have no effect, except as noted under 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. If and are set in oflag and the named shared memory object exists, will fail. The flag is ignored if is not set in oflag. If the shared memory object exists, and it is successfully opened for reading and writing set in oflag), the object will be truncated to zero length. The mode and owner shall remain unchanged by this function call. RETURN VALUE
returns the following values: n Successful completion. n is the lowest numbered unused file descriptor for the process. Failure. is set to indicate the error. ERRORS
If fails, is set to one of the following values: 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 is speci- fied and write permission is denied. The and are set in oflag and the named shared memory object already exists. The operation was interrupted by a signal. The operation is not supported for the given name. Too many file descriptors are currently in use by this process. The length of the name string exceeds or the length of a (pathname) component of the name string exceeds while is in effect. Too many shared memory objects are currently open in the system. The flag is not set in oflag and the named shared memory object does not exist. There are insufficient resources for the creation of the new shared memory object. is not supported by the implementation. SEE ALSO
shm_unlink(2), close(2), mmap(2), munmap(2), privileges(5). STANDARDS CONFORMANCE
shm_open(2)

Check Out this Related Man Page

SHM_OPEN(3)						     Linux Programmer's Manual						       SHM_OPEN(3)

NAME
shm_open, shm_unlink - create/open or unlink POSIX shared memory objects SYNOPSIS
#include <sys/mman.h> #include <sys/stat.h> /* For mode constants */ #include <fcntl.h> /* For O_* constants */ int shm_open(const char *name, int oflag, mode_t mode); int shm_unlink(const char *name); Link with -lrt. DESCRIPTION
shm_open() creates and opens a new, or opens an existing, POSIX shared memory object. A POSIX shared memory object is in effect a handle which can be used by unrelated processes to mmap(2) the same region of shared memory. The shm_unlink() function performs the converse operation, removing an object previously created by shm_open(). The operation of shm_open() is analogous to that of open(2). name specifies the shared memory object to be created or opened. For porta- ble use, a shared memory object should be identified by a name of the form /somename; that is, a null-terminated string of up to NAME_MAX (i.e., 255) characters consisting of an initial slash, followed by one or more characters, none of which are slashes. oflag is a bit mask created by ORing together exactly one of O_RDONLY or O_RDWR and any of the other flags listed here: O_RDONLY Open the object for read access. A shared memory object opened in this way can only be mmap(2)ed for read (PROT_READ) access. O_RDWR Open the object for read-write access. O_CREAT Create the shared memory object if it does not exist. The user and group ownership of the object are taken from the correspond- ing effective IDs of the calling process, and the object's permission bits are set according to the low-order 9 bits of mode, except that those bits set in the process file mode creation mask (see umask(2)) are cleared for the new object. A set of macro constants which can be used to define mode is listed in open(2). (Symbolic definitions of these constants can be obtained by including <sys/stat.h>.) A new shared memory object initially has zero length--the size of the object can be set using ftruncate(2). The newly allocated bytes of a shared memory object are automatically initialized to 0. O_EXCL If O_CREAT was also specified, and a shared memory object with the given name already exists, return an error. The check for the existence of the object, and its creation if it does not exist, are performed atomically. O_TRUNC If the shared memory object already exists, truncate it to zero bytes. Definitions of these flag values can be obtained by including <fcntl.h>. On successful completion shm_open() returns a new file descriptor referring to the shared memory object. This file descriptor is guaran- teed to be the lowest-numbered file descriptor not previously opened within the process. The FD_CLOEXEC flag (see fcntl(2)) is set for the file descriptor. The file descriptor is normally used in subsequent calls to ftruncate(2) (for a newly created object) and mmap(2). After a call to mmap(2) the file descriptor may be closed without affecting the memory mapping. The operation of shm_unlink() is analogous to unlink(2): it removes a shared memory object name, and, once all processes have unmapped the object, de-allocates and destroys the contents of the associated memory region. After a successful shm_unlink(), attempts to shm_open() an object with the same name will fail (unless O_CREAT was specified, in which case a new, distinct object is created). RETURN VALUE
On success, shm_open() returns a nonnegative file descriptor. On failure, shm_open() returns -1. shm_unlink() returns 0 on success, or -1 on error. ERRORS
On failure, errno is set to indicate the cause of the error. Values which may appear in errno include the following: EACCES Permission to shm_unlink() the shared memory object was denied. EACCES Permission was denied to shm_open() name in the specified mode, or O_TRUNC was specified and the caller does not have write permis- sion on the object. EEXIST Both O_CREAT and O_EXCL were specified to shm_open() and the shared memory object specified by name already exists. EINVAL The name argument to shm_open() was invalid. EMFILE The process already has the maximum number of files open. ENAMETOOLONG The length of name exceeds PATH_MAX. ENFILE The limit on the total number of files open on the system has been reached. ENOENT An attempt was made to shm_open() a name that did not exist, and O_CREAT was not specified. ENOENT An attempt was to made to shm_unlink() a name that does not exist. VERSIONS
These functions are provided in glibc 2.2 and later. CONFORMING TO
POSIX.1-2001. POSIX.1-2001 says that the group ownership of a newly created shared memory object is set to either the calling process's effective group ID or "a system default group ID". NOTES
POSIX leaves the behavior of the combination of O_RDONLY and O_TRUNC unspecified. On Linux, this will successfully truncate an existing shared memory object--this may not be so on other UNIX systems. The POSIX shared memory object implementation on Linux 2.4 makes use of a dedicated file system, which is normally mounted under /dev/shm. SEE ALSO
close(2), fchmod(2), fchown(2), fcntl(2), fstat(2), ftruncate(2), mmap(2), open(2), umask(2), shm_overview(7) COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2009-02-25 SHM_OPEN(3)
Man Page