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 <mtk16@ext.canterbury.ac.nz>
29 .TH SHMOP 2 2002-01-05 "Linux 2.5" "Linux Programmer's Manual"
31 shmop \- shared memory operations
35 #include <sys/types.h>
40 .BI "void *shmat(int " shmid ,
41 .BI "const void *" shmaddr ,
44 .BI "int shmdt(const void *" shmaddr );
48 attaches the shared memory segment identified by
50 to the address space of the calling process.
51 The attaching address is specified by
53 with one of the following criteria:
59 the system chooses a suitable (unused) address at which to attach
70 the attach occurs at the address equal to
72 rounded down to the nearest multiple of
76 must be a page aligned address at which the attach occurs.
82 the segment is attached for reading and the process must have
83 read permission for the segment.
84 Otherwise the segment is attached for read and write
85 and the process must have read and write permission for the segment.
86 There is no notion of write-only shared memory segment.
90 value of the calling process is not altered by the attach.
91 The segment will automatically be detached at process exit.
92 The same segment may be attached as a read and as a read-write
93 one, and more than once, in the process's address space.
97 call the system updates the members of the
99 structure associated to the shared memory segment as follows:
102 is set to the current time.
105 is set to the process-ID of the calling process.
108 is incremented by one.
110 Note that the attach succeeds also if the shared memory segment is
111 marked to be deleted.
115 detaches the shared memory segment located at the address specified by
117 from the address space of the calling process.
118 The to\-be\-detached segment must be currently
121 equal to the value returned by the its attaching
127 call the system updates the members of the
129 structure associated with the shared memory segment as follows:
132 is set to the current time.
135 is set to the process-ID of the calling process.
138 is decremented by one.
139 If it becomes 0 and the segment is marked for deletion,
140 the segment is deleted.
142 The occupied region in the user space of the calling process is
149 the child inherits the attached shared memory segments.
154 all attached shared memory segments are detached from the process.
159 all attached shared memory segments are detached from the process.
161 On failure both functions return
165 indicating the error.
168 returns the address of the attached shared memory segment, and
177 is set to one of the following:
180 The calling process has no access permissions for the requested attach
186 value, unaligned (i.e., not page-aligned and \fBSHM_RND\fP was not
187 specified) or invalid
189 value, or failing attach at
193 Could not allocate memory for the descriptor or for the page tables.
197 can fail only if there is no shared memory segment attached at
199 in such a case at return
203 .\" Actually the above is what *should* be done, according to POSIX.
204 .\" However as at kernel 2.2.19, and 2.4.15, shmdt() never returns an
205 .\" error, even if shmaddr is invalid. (MTK, Jan 2002)
213 is the preferred, portable way of attaching a shared memory segment.
214 Be aware that the shared memory segment attached in this way
215 may be attached at different addresses in different processes.
216 Therefore, any pointers maintained within the shared memory must be
217 made relative (typically to the starting address of the segment),
218 rather than absolute.
220 The following system parameter affects a
225 Segment low boundary address multiple.
226 Must be page aligned.
227 For the current implementation the
232 The implementation has no intrinsic limit to the per\-process maximum
233 number of shared memory segments
236 SVr4, SVID. SVr4 documents an additional error condition EMFILE.
237 In SVID-v4 the type of the \fIshmaddr\fP argument was changed from
241 and the returned type of \fIshmat\fP() from
245 (Linux libc4 and libc5 have the
247 prototypes; glibc2 has