.\" .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for .\" permission to reproduce portions of its copyrighted documentation. .\" Original documentation from The Open Group can be obtained online at .\" http://www.opengroup.org/bookstore/. .\" .\" The Institute of Electrical and Electronics Engineers and The Open .\" Group, have given us permission to reprint portions of their .\" documentation. .\" .\" In the following statement, the phrase ``this text'' refers to portions .\" of the system documentation. .\" .\" Portions of this text are reprinted and reproduced in electronic form .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, .\" Standard for Information Technology -- Portable Operating System .\" Interface (POSIX), The Open Group Base Specifications Issue 6, .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics .\" Engineers, Inc and The Open Group. In the event of any discrepancy .\" between these versions and the original IEEE and The Open Group .\" Standard, the original IEEE and The Open Group Standard is the referee .\" document. The original Standard can be obtained online at .\" http://www.opengroup.org/unix/online.html. .\" .\" This notice shall appear on any product containing this material. .\" .\" The contents of this file are subject to the terms of the .\" Common Development and Distribution License (the "License"). .\" You may not use this file except in compliance with the License. .\" .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE .\" or http://www.opensolaris.org/os/licensing. .\" See the License for the specific language governing permissions .\" and limitations under the License. .\" .\" When distributing Covered Code, include this CDDL HEADER in each .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. .\" If applicable, add the following below this CDDL HEADER, with the .\" fields enclosed by brackets "[]" replaced with your own identifying .\" information: Portions Copyright [yyyy] [name of copyright owner] .\" .\" .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. .\" .TH SHM_OPEN 3C "Feb 5, 2008" .SH NAME shm_open \- open a shared memory object .SH SYNOPSIS .LP .nf #include \fBint\fR \fBshm_open\fR(\fBconst char *\fR\fIname\fR, \fBint\fR \fIoflag\fR, \fBmode_t\fR \fImode\fR); .fi .SH DESCRIPTION .sp .LP The \fBshm_open()\fR function establishes a connection between a shared memory object and a file descriptor. It creates an open file description that refers to the shared memory object and a file descriptor that refers to that open file description. The file descriptor is used by other functions to refer to that shared memory object. The \fIname\fR argument points to a string naming a shared memory object. It is unspecified whether the name appears in the file system and is visible to other functions that take pathnames as arguments. The \fIname\fR argument conforms to the construction rules for a pathname. The first character of \fIname\fR must be a slash (/) character and the remaining characters of \fIname\fR cannot include any slash characters. For maximum portability, \fIname\fR should include no more than 14 characters, but this limit is not enforced. .sp .LP If successful, \fBshm_open()\fR returns a file descriptor for the shared memory object that is the lowest numbered file descriptor not currently open for that process. The open file description is new, and therefore the file descriptor does not share it with any other processes. It is unspecified whether the file offset is set. The \fBFD_CLOEXEC\fR file descriptor flag associated with the new file descriptor is set. .sp .LP The file status flags and file access modes of the open file description are according to the value of \fIoflag\fR. The \fIoflag\fR argument is the bitwise inclusive OR of the following flags defined in the header <\fBfcntl.h\fR>. Applications specify exactly one of the first two values (access modes) below in the value of \fIoflag\fR: .sp .ne 2 .na \fB\fBO_RDONLY\fR \fR .ad .RS 13n Open for read access only. .RE .sp .ne 2 .na \fB\fBO_RDWR\fR \fR .ad .RS 13n Open for read or write access. .RE .sp .LP Any combination of the remaining flags may be specified in the value of \fIoflag\fR: .sp .ne 2 .na \fB\fBO_CREAT\fR \fR .ad .RS 12n If the shared memory object exists, this flag has no effect, except as noted under \fBO_EXCL\fR below. Otherwise the shared memory object is created; the user \fBID\fR of the shared memory object will be set to the effective user \fBID\fR of the process; the group \fBID\fR of the shared memory object will be set to a system default group \fBID\fR or to the effective group \fBID\fR of the process. The permission bits of the shared memory object will be set to the value of the \fImode\fR argument except those set in the file mode creation mask of the process. When bits in \fImode\fR other than the file permission bits are set, the effect is unspecified. The \fImode\fR argument does not affect whether the shared memory object is opened for reading, for writing, or for both. The shared memory object has a size of zero. .RE .sp .ne 2 .na \fB\fBO_EXCL\fR \fR .ad .RS 12n If \fBO_EXCL\fR and \fBO_CREAT\fR are set, \fBshm_open()\fR fails if the shared memory object exists. The check for the existence of the shared memory object and the creation of the object if it does not exist is atomic with respect to other processes executing \fBshm_open()\fR naming the same shared memory object with \fBO_EXCL\fR and \fBO_CREAT\fR set. If \fBO_EXCL\fR is set and \fBO_CREAT\fR is not set, the result is undefined. .RE .sp .ne 2 .na \fB\fBO_TRUNC\fR \fR .ad .RS 12n If the shared memory object exists, and it is successfully opened \fBO_RDWR\fR, the object will be truncated to zero length and the mode and owner will be unchanged by this function call. The result of using \fBO_TRUNC\fR with \fBO_RDONLY\fR is undefined. .RE .sp .LP When a shared memory object is created, the state of the shared memory object, including all data associated with the shared memory object, persists until the shared memory object is unlinked and all other references are gone. It is unspecified whether the name and shared memory object state remain valid after a system reboot. .SH RETURN VALUES .sp .LP Upon successful completion, the \fBshm_open()\fR function returns a non-negative integer representing the lowest numbered unused file descriptor. Otherwise, it returns \fB\(mi1\fR and sets \fBerrno\fR to indicate the error condition. .SH ERRORS .sp .LP The \fBshm_open()\fR function will fail if: .sp .ne 2 .na \fB\fBEACCES\fR \fR .ad .RS 17n The shared memory object exists and the permissions specified by \fIoflag\fR are denied, or the shared memory object does not exist and permission to create the shared memory object is denied, or \fBO_TRUNC\fR is specified and write permission is denied. .RE .sp .ne 2 .na \fB\fBEEXIST\fR \fR .ad .RS 17n \fBO_CREAT\fR and \fBO_EXCL\fR are set and the named shared memory object already exists. .RE .sp .ne 2 .na \fB\fBEINTR\fR \fR .ad .RS 17n The \fBshm_open()\fR operation was interrupted by a signal. .RE .sp .ne 2 .na \fB\fBEINVAL\fR \fR .ad .RS 17n The \fBshm_open()\fR operation is not supported for the given name. .RE .sp .ne 2 .na \fB\fBEMFILE\fR \fR .ad .RS 17n Too many file descriptors are currently in use by this process. .RE .sp .ne 2 .na \fB\fBENAMETOOLONG\fR \fR .ad .RS 17n The length of the \fIname\fR string exceeds \fBPATH_MAX\fR, or a pathname component is longer than \fINAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in effect. .RE .sp .ne 2 .na \fB\fBENFILE\fR \fR .ad .RS 17n Too many shared memory objects are currently open in the system. .RE .sp .ne 2 .na \fB\fBENOENT\fR \fR .ad .RS 17n \fBO_CREAT\fR is not set and the named shared memory object does not exist. .RE .sp .ne 2 .na \fB\fBENOSPC\fR \fR .ad .RS 17n There is insufficient space for the creation of the new shared memory object. .RE .sp .ne 2 .na \fB\fBENOSYS\fR \fR .ad .RS 17n The \fBshm_open()\fR function is not supported by the system. .RE .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS box; c | c l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed _ MT-Level MT-Safe _ Standard See \fBstandards\fR(5). .TE .SH SEE ALSO .sp .LP \fBclose\fR(2), \fBdup\fR(2), \fBexec\fR(2), \fBfcntl\fR(2), \fBmmap\fR(2), \fBumask\fR(2), \fBshm_unlink\fR(3C), \fBsysconf\fR(3C), \fBfcntl.h\fR(3HEAD), \fBattributes\fR(5), \fBstandards\fR(5) .SH NOTES .sp .LP Solaris 2.6 was the first release to support the Asynchronous Input and Output option. Prior to this release, this function always returned \fB\(mi1\fR and set \fBerrno\fR to \fBENOSYS\fR.