1 .\" Copyright (c) 1993 Luigi P. Bai (lpb@softint.com) July 28, 1993
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 Wed Jul 28 10:57:35 1993, Rik Faith <faith@cs.unc.edu>
24 .\" Modified Sun Nov 28 16:43:30 1993, Rik Faith <faith@cs.unc.edu>
25 .\" with material from Giorgio Ciucci <giorgio@crcc.it>
26 .\" Portions Copyright 1993 Giorgio Ciucci <giorgio@crcc.it>
27 .\" Modified Tue Oct 22 22:03:17 1996 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified, 8 Jan 2003, Michael Kerrisk, <mtk.manpages@gmail.com>
29 .\" Removed EIDRM from errors - that can't happen...
30 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Added notes on capability requirements
32 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Language and formatting clean-ups
34 .\" Added notes on /proc files
36 .TH SHMGET 2 2012-05-31 "Linux" "Linux Programmer's Manual"
38 shmget \- allocates a shared memory segment
41 .B #include <sys/ipc.h>
43 .B #include <sys/shm.h>
45 .BI "int shmget(key_t " key ", size_t " size ", int " shmflg );
49 returns the identifier of the shared memory segment
50 associated with the value of the argument
52 A new shared memory segment, with size equal to the value of
54 rounded up to a multiple of
64 no shared memory segment corresponding to
77 and a shared memory segment already exists for
85 (This is analogous to the effect of the combination
95 to create a new segment.
96 If this flag is not used, then
98 will find the segment associated with \fIkey\fP and check to see if
99 the user has permission to access the segment.
102 used with \fBIPC_CREAT\fP to ensure failure if the segment already exists.
105 (least significant 9 bits)
106 specifying the permissions granted to the owner, group, and world.
107 These bits have the same format, and the same
112 Presently, the execute permissions are not used by the system.
114 .BR SHM_HUGETLB " (since Linux 2.6)"
115 Allocate the segment using "huge pages."
116 See the Linux kernel source file
117 .I Documentation/vm/hugetlbpage.txt
118 for further information.
120 .BR SHM_NORESERVE " (since Linux 2.6.15)"
121 This flag serves the same purpose as the
125 Do not reserve swap space for this segment.
126 When swap space is reserved, one has the guarantee
127 that it is possible to modify the segment.
128 When swap space is not reserved one might get
131 if no physical memory is available.
132 See also the discussion of the file
133 .I /proc/sys/vm/overcommit_memory
136 .\" As at 2.6.17-rc2, this flag has no effect if SHM_HUGETLB was also
139 When a new shared memory segment is created,
140 its contents are initialized to zero values, and
141 its associated data structure,
145 is initialized as follows:
150 are set to the effective user ID of the calling process.
155 are set to the effective group ID of the calling process.
157 The least significant 9 bits of
159 are set to the least significant 9 bit of
163 is set to the value of
174 is set to the current time.
176 If the shared memory segment already exists, the permissions are
177 verified, and a check is made to see if it is marked for destruction.
179 A valid segment identifier,
181 is returned on success, \-1 on error.
185 is set to one of the following:
188 The user does not have permission to access the
189 shared memory segment, and does not have the
194 .B IPC_CREAT | IPC_EXCL
195 was specified and the segment exists.
198 A new segment was to be created and \fIsize\fP < \fBSHMMIN\fP
199 or \fIsize\fP > \fBSHMMAX\fP, or no new segment was to be created,
200 a segment with given key existed, but \fIsize\fP is greater than the size
204 .\" [2.6.7] shmem_zero_setup()-->shmem_file_setup()-->get_empty_filp()
205 The system limit on the total number of open files has been reached.
208 No segment exists for the given \fIkey\fP, and
213 No memory could be allocated for segment overhead.
216 All possible shared memory IDs have been taken
218 or allocating a segment of the requested
220 would cause the system to exceed the system-wide limit on shared memory
226 flag was specified, but the caller was not privileged (did not have the
231 .\" SVr4 documents an additional error condition EEXIST.
234 is a nonportable Linux extension.
240 isn't required on Linux or by any version of POSIX.
242 some old implementations required the inclusion of these header files,
243 and the SVID also documented their inclusion.
244 Applications intended to be portable to such old systems may need
245 to include these header files.
246 .\" Like Linux, the FreeBSD man pages still document
247 .\" the inclusion of these header files.
250 isn't a flag field but a
253 If this special value is used for
255 the system call ignores everything but the least significant 9 bits of
257 and creates a new shared memory segment (on success).
259 The following limits on shared memory segment resources affect the
264 System wide maximum of shared memory pages
265 (on Linux, this limit can be read and modified via
266 .IR /proc/sys/kernel/shmall ).
269 Maximum size in bytes for a shared memory segment: policy dependent
270 (on Linux, this limit can be read and modified via
271 .IR /proc/sys/kernel/shmmax ).
274 Minimum size in bytes for a shared memory segment: implementation
275 dependent (currently 1 byte, though
277 is the effective minimum size).
280 System wide maximum number of shared memory segments: implementation
281 dependent (currently 4096, was 128 before Linux 2.3.99;
282 on Linux, this limit can be read and modified via
283 .IR /proc/sys/kernel/shmmni ).
284 .\" Kernels between 2.4.x and 2.6.8 had an off-by-one error that meant
285 .\" that we could create one more segment than SHMMNI -- MTK
286 .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
288 The implementation has no specific limits for the per-process maximum
289 number of shared memory segments
292 Until version 2.3.30 Linux would return
296 on a shared memory segment scheduled for deletion.
300 was perhaps unfortunate,
302 would more clearly show its function.
308 .BR capabilities (7),
309 .BR shm_overview (7),