1 .\" Copyright (C) 2002 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" FIXME . Add an example to this page
26 .TH SHM_OPEN 3 2009-02-25 "Linux" "Linux Programmer's Manual"
28 shm_open, shm_unlink \- create/open or unlink POSIX shared memory objects
30 .B #include <sys/mman.h>
32 .BR "#include <sys/stat.h>" " /* For mode constants */"
34 .BR "#include <fcntl.h>" " /* For O_* constants */"
36 .BI "int shm_open(const char *" name ", int " oflag ", mode_t " mode );
38 .BI "int shm_unlink(const char *" name );
40 Link with \fI\-lrt\fP.
43 creates and opens a new, or opens an existing, POSIX shared memory object.
44 A POSIX shared memory object is in effect a handle which can
45 be used by unrelated processes to
47 the same region of shared memory.
50 function performs the converse operation,
51 removing an object previously created by
56 is analogous to that of
59 specifies the shared memory object to be created or opened.
61 a shared memory object should be identified by a name of the form
63 that is, a null-terminated string of up to
65 (i.e., 255) characters consisting of an initial slash,
66 .\" glibc allows the initial slash to be omitted, and makes
67 .\" multiple initial slashes equivalent to a single slash.
68 .\" This differs from the implementation of POSIX message queues.
69 followed by one or more characters, none of which are slashes.
70 .\" glibc allows subdirectory components in the name, in which
71 .\" case the subdirectory must exist under /dev/shm, and allow the
72 .\" required permissions if a user wants to create a shared memory
73 .\" object in that subdirectory.
76 is a bit mask created by ORing together exactly one of
80 and any of the other flags listed here:
83 Open the object for read access.
84 A shared memory object opened in this way can be
86 only for read (\fBPROT_READ\fP) access.
89 Open the object for read-write access.
92 Create the shared memory object if it does not exist.
93 The user and group ownership of the object are taken
94 from the corresponding effective IDs of the calling process,
95 .\" In truth it is actually the file system IDs on Linux, but these
96 .\" are nearly always the same as the effective IDs. (MTK, Jul 05)
98 permission bits are set according to the low-order 9 bits of
100 except that those bits set in the process file mode
103 are cleared for the new object.
104 A set of macro constants which can be used to define
108 (Symbolic definitions of these constants can be obtained by including
111 A new shared memory object initially has zero length\(emthe size of the
112 object can be set using
114 The newly allocated bytes of a shared memory
115 object are automatically initialized to 0.
120 was also specified, and a shared memory object with the given
122 already exists, return an error.
123 The check for the existence of the object, and its creation if it
124 does not exist, are performed atomically.
127 If the shared memory object already exists, truncate it to zero bytes.
129 Definitions of these flag values can be obtained by including
132 On successful completion
134 returns a new file descriptor referring to the shared memory object.
135 This file descriptor is guaranteed to be the lowest-numbered file descriptor
136 not previously opened within the process.
141 is set for the file descriptor.
143 The file descriptor is normally used in subsequent calls
146 (for a newly created object) and
150 the file descriptor may be closed without affecting the memory mapping.
157 it removes a shared memory object name, and, once all processes
158 have unmapped the object, de-allocates and
159 destroys the contents of the associated memory region.
164 an object with the same
168 was specified, in which case a new, distinct object is created).
172 returns a nonnegative file descriptor.
177 returns 0 on success, or \-1 on error.
181 is set to indicate the cause of the error.
182 Values which may appear in
184 include the following:
189 the shared memory object was denied.
192 Permission was denied to
199 was specified and the caller does not have write permission on the object.
208 and the shared memory object specified by
220 The process already has the maximum number of files open.
229 The limit on the total number of files open on the system has been
233 An attempt was made to
237 that did not exist, and
242 An attempt was to made to
248 These functions are provided in glibc 2.2 and later.
252 POSIX.1-2001 says that the group ownership of a newly created shared
253 memory object is set to either the calling process's effective group ID
254 or "a system default group ID".
257 POSIX leaves the behavior of the combination of
262 On Linux, this will successfully truncate an existing
263 shared memory object\(emthis may not be so on other UNIX systems.
265 The POSIX shared memory object implementation on Linux 2.4 makes use
266 of a dedicated file system, which is normally