1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Modified Sun Nov 28 17:06:19 1993, Rik Faith (faith@cs.unc.edu)
24 .\" with material from Luigi P. Bai (lpb@softint.com)
25 .\" Portions Copyright 1993 Luigi P. Bai
26 .\" Modified Tue Oct 22 22:04:23 1996 by Eric S. Raymond <esr@thyrsus.com>
27 .\" Modified, 5 Jan 2002, Michael Kerrisk <mtk-manpages@gmx.net>
28 .\" Modified, 19 Sep 2002, Michael Kerrisk <mtk-manpages@gmx.net>
29 .\" Added SHM_REMAP flag description
30 .\" Modified, 27 May 2004, Michael Kerrisk <mtk-manpages@gmx.net>
31 .\" Added notes on capability requirements
32 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk-manpages@gmx.net>
33 .\" Language and formatting clean-ups
34 .\" Changed wording and placement of sentence regarding attachment
35 .\" of segments marked for destruction
37 .TH SHMOP 2 2004-11-10 "Linux 2.6.9" "Linux Programmer's Manual"
39 shmop, shmat, shmdt \- shared memory operations
43 #include <sys/types.h>
48 .BI "void *shmat(int " shmid ,
49 .BI "const void *" shmaddr ,
52 .BI "int shmdt(const void *" shmaddr );
55 attaches the shared memory segment identified by
57 to the address space of the calling process.
58 The attaching address is specified by
60 with one of the following criteria:
65 the system chooses a suitable (unused) address at which to attach
75 the attach occurs at the address equal to
77 rounded down to the nearest multiple of
81 must be a page-aligned address at which the attach occurs.
87 the segment is attached for reading and the process must have
88 read permission for the segment.
89 Otherwise the segment is attached for read and write
90 and the process must have read and write permission for the segment.
91 There is no notion of a write-only shared memory segment.
95 flag may be specified in
97 to indicate that the mapping of the segment should replace
98 any existing mapping in the range starting at
100 and continuing for the size of the segment.
103 error would result if a mapping already exists in this address range.)
110 value of the calling process is not altered by the attach.
111 The segment will automatically be detached at process exit.
112 The same segment may be attached as a read and as a read-write
113 one, and more than once, in the process's address space.
117 call updates the members of the
121 associated with the shared memory segment as follows:
124 is set to the current time.
127 is set to the process-ID of the calling process.
130 is incremented by one.
133 detaches the shared memory segment located at the address specified by
135 from the address space of the calling process.
136 The to\-be\-detached segment must be currently
139 equal to the value returned by the attaching
145 call the system updates the members of the
147 structure associated with the shared memory segment as follows:
150 is set to the current time.
153 is set to the process-ID of the calling process.
156 is decremented by one.
157 If it becomes 0 and the segment is marked for deletion,
158 the segment is deleted.
162 the child inherits the attached shared memory segments.
166 all attached shared memory segments are detached from the process.
170 all attached shared memory segments are detached from the process.
174 returns the address of the attached shared memory segment; on error
178 is set to indicate the cause of the error.
182 returns 0; on error \-1 is returned, and
184 is set to indicate the cause of the error.
190 is set to one of the following:
193 The calling process does not have the required permissions for
194 the requested attach type, and does not have the
201 value, unaligned (i.e., not page-aligned and \fBSHM_RND\fP was not
202 specified) or invalid
204 value, or failing attach at
206 .\" FIXME What does "failing attach at brk" mean? (Is this phrase
215 Could not allocate memory for the descriptor or for the page tables.
224 There is no shared memory segment attached at
227 .\" The following since 2.6.17-rc1:
229 is not aligned on a page boundary.
232 .\" SVr4 documents an additional error condition EMFILE.
234 In SVID 3 (or perhaps earlier)
235 the type of the \fIshmaddr\fP argument was changed from
239 and the returned type of
245 (Linux libc4 and libc5 have the
247 prototypes; glibc2 has
255 is the preferred, portable way of attaching a shared memory segment.
256 Be aware that the shared memory segment attached in this way
257 may be attached at different addresses in different processes.
258 Therefore, any pointers maintained within the shared memory must be
259 made relative (typically to the starting address of the segment),
260 rather than absolute.
262 On Linux, it is possible to attach a shared memory segment even if it
263 is already marked to be deleted.
264 However, POSIX.1-2001 does not specify this behaviour and
265 many other implementations do not support it.
267 The following system parameter affects
270 .\" FIXME A good explanation of the rationale for the existence
271 .\" of SHMLBA would be useful here
273 Segment low boundary address multiple.
274 Must be page aligned.
275 For the current implementation the
279 .\" FIXME That last sentence isn't true for all Linux
280 .\" architectures (i.e., SHMLBA != PAGE_SIZE for some architectures)
283 The implementation places no intrinsic limit on the per\-process maximum
284 number of shared memory segments
291 .BR capabilities (7),