]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (c) 1993 Luigi P. Bai (lpb@softint.com) July 28, 1993 |
2 | .\" | |
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. | |
6 | .\" | |
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. | |
c13182ef | 11 | .\" |
fea681da MK |
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 | |
18 | .\" professionally. | |
c13182ef | 19 | .\" |
fea681da MK |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" | |
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> | |
305a0578 | 28 | .\" Modified, 8 Jan 2003, Michael Kerrisk, <mtk-manpages@gmx.net> |
fea681da | 29 | .\" Removed EIDRM from errors - that can't happen... |
305a0578 | 30 | .\" Modified, 27 May 2004, Michael Kerrisk <mtk-manpages@gmx.net> |
fea681da | 31 | .\" Added notes on capability requirements |
c952e226 MK |
32 | .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk-manpages@gmx.net> |
33 | .\" Language and formatting clean-ups | |
34 | .\" Added notes on /proc files | |
fea681da | 35 | .\" |
d9343c5c | 36 | .TH SHMGET 2 2006-05-02 "Linux" "Linux Programmer's Manual" |
fea681da MK |
37 | .SH NAME |
38 | shmget \- allocates a shared memory segment | |
39 | .SH SYNOPSIS | |
40 | .ad l | |
41 | .B #include <sys/ipc.h> | |
fea681da MK |
42 | .B #include <sys/shm.h> |
43 | .sp | |
f7174672 | 44 | .BI "int shmget(key_t " key ", size_t " size ", int " shmflg ); |
fea681da MK |
45 | .ad b |
46 | .SH DESCRIPTION | |
c952e226 | 47 | .BR shmget () |
fea681da MK |
48 | returns the identifier of the shared memory segment |
49 | associated with the value of the argument | |
50 | .IR key . | |
51 | A new shared memory segment, with size equal to the value of | |
52 | .I size | |
53 | rounded up to a multiple of | |
54 | .BR PAGE_SIZE , | |
55 | is created if | |
56 | .I key | |
57 | has the value | |
58 | .B IPC_PRIVATE | |
59 | or | |
60 | .I key | |
61 | isn't | |
62 | .BR IPC_PRIVATE , | |
63 | no shared memory segment corresponding to | |
64 | .IR key | |
65 | exists, and | |
66 | .B IPC_CREAT | |
c952e226 MK |
67 | is specified in |
68 | .IR shmflg . | |
69 | .PP | |
70 | If | |
fea681da | 71 | .I shmflg |
c952e226 MK |
72 | specifies both |
73 | .B IPC_CREAT | |
74 | and | |
75 | .B IPC_EXCL | |
76 | and a shared memory segment already exists for | |
77 | .IR key , | |
78 | then | |
79 | .BR shmget () | |
c13182ef | 80 | fails with |
c952e226 MK |
81 | .I errno |
82 | set to | |
83 | .BR EEXIST . | |
c13182ef | 84 | (This is analogous to the effect of the combination |
c952e226 MK |
85 | .B O_CREAT | O_EXCL |
86 | for | |
87 | .BR open (2).) | |
fea681da MK |
88 | .PP |
89 | The value | |
90 | .I shmflg | |
91 | is composed of: | |
92 | .TP 12 | |
93 | .B IPC_CREAT | |
c13182ef MK |
94 | to create a new segment. |
95 | If this flag is not used, then | |
c952e226 | 96 | .BR shmget () |
c13182ef | 97 | will find the segment associated with \fIkey\fP and check to see if |
fea681da MK |
98 | the user has permission to access the segment. |
99 | .TP | |
100 | .B IPC_EXCL | |
c13182ef | 101 | used with \fBIPC_CREAT\fP to ensure failure if the segment already exists. |
fea681da | 102 | .TP |
c13182ef | 103 | .I mode_flags |
c952e226 | 104 | (least significant 9 bits) |
fea681da | 105 | specifying the permissions granted to the owner, group, and world. |
c952e226 MK |
106 | These bits have the same format, and the same |
107 | meaning, as the | |
108 | .I mode | |
109 | argument of | |
110 | .BR open (2). | |
fea681da | 111 | Presently, the execute permissions are not used by the system. |
eb57338f | 112 | .TP |
32047971 | 113 | .BR SHM_HUGETLB " (since Linux 2.6)" |
c13182ef | 114 | Allocate the segment using "huge pages." |
eb57338f MK |
115 | See the kernel source file |
116 | .I Documentation/vm/hugetlbpage.txt | |
117 | for further information. | |
32047971 MK |
118 | .TP |
119 | .BR SHM_NORESERVE " (since Linux 2.6.15)" | |
120 | This flag serves the same purpose as the | |
121 | .BR mmap (2) | |
122 | .B MAP_NORESERVE | |
123 | flag. | |
c13182ef | 124 | Do not reserve swap space for this segment. |
32047971 MK |
125 | When swap space is reserved, one has the guarantee |
126 | that it is possible to modify the segment. | |
127 | When swap space is not reserved one might get SIGSEGV upon a write | |
128 | if no physical memory is available. | |
129 | See also the discussion of the file | |
130 | .I /proc/sys/vm/overcommit_memory | |
c13182ef | 131 | in |
defcceb3 | 132 | .BR proc (5). |
32047971 MK |
133 | .\" As at 2.6.17-rc2, this flag has no effect if SHM_HUGETLB was also |
134 | .\" specified. | |
fea681da | 135 | .PP |
6319e935 MK |
136 | When a new shared memory segment is created, |
137 | its contents are initialised to zero values, and | |
138 | its associated data structure, | |
fea681da | 139 | .I shmid_ds |
c952e226 | 140 | (see |
6319e935 | 141 | .BR shmctl (2)), |
c952e226 | 142 | is initialised as follows: |
fea681da | 143 | .IP |
c952e226 | 144 | .I shm_perm.cuid |
fea681da | 145 | and |
c952e226 | 146 | .I shm_perm.uid |
499d62f2 | 147 | are set to the effective user ID of the calling process. |
fea681da | 148 | .IP |
c952e226 | 149 | .I shm_perm.cgid |
fea681da | 150 | and |
c952e226 | 151 | .I shm_perm.gid |
499d62f2 | 152 | are set to the effective group ID of the calling process. |
fea681da | 153 | .IP |
c952e226 MK |
154 | The least significant 9 bits of |
155 | .I shm_perm.mode | |
156 | are set to the least significant 9 bit of | |
fea681da MK |
157 | .IR shmflg . |
158 | .IP | |
c952e226 | 159 | .I shm_segsz |
fea681da MK |
160 | is set to the value of |
161 | .IR size . | |
162 | .IP | |
c952e226 MK |
163 | .IR shm_lpid , |
164 | .IR shm_nattch , | |
165 | .I shm_atime | |
fea681da | 166 | and |
c952e226 MK |
167 | .I shm_dtime |
168 | are set to 0. | |
fea681da | 169 | .IP |
c952e226 | 170 | .I shm_ctime |
fea681da MK |
171 | is set to the current time. |
172 | .PP | |
c952e226 | 173 | If the shared memory segment already exists, the permissions are |
fea681da | 174 | verified, and a check is made to see if it is marked for destruction. |
fea681da MK |
175 | .SH "RETURN VALUE" |
176 | A valid segment identifier, | |
177 | .IR shmid , | |
178 | is returned on success, \-1 on error. | |
179 | .SH ERRORS | |
180 | On failure, | |
c952e226 | 181 | .I errno |
fea681da MK |
182 | is set to one of the following: |
183 | .TP 12 | |
184 | .B EACCES | |
c13182ef | 185 | The user does not have permission to access the |
fea681da MK |
186 | shared memory segment, and does not have the |
187 | .B CAP_IPC_OWNER | |
188 | capability. | |
189 | .TP | |
190 | .B EEXIST | |
191 | .B IPC_CREAT | IPC_EXCL | |
192 | was specified and the segment exists. | |
193 | .TP | |
fea681da MK |
194 | .B EINVAL |
195 | A new segment was to be created and \fIsize\fP < \fBSHMMIN\fP | |
196 | or \fIsize\fP > \fBSHMMAX\fP, or no new segment was to be created, | |
197 | a segment with given key existed, but \fIsize\fP is greater than the size | |
198 | of that segment. | |
199 | .TP | |
200 | .B ENFILE | |
201 | .\" [2.6.7] shmem_zero_setup()-->shmem_file_setup()-->get_empty_filp() | |
202 | The system limit on the total number of open files has been reached. | |
203 | .TP | |
204 | .B ENOENT | |
205 | No segment exists for the given \fIkey\fP, and | |
206 | .B IPC_CREAT | |
207 | was not specified. | |
208 | .TP | |
209 | .B ENOMEM | |
210 | No memory could be allocated for segment overhead. | |
211 | .TP | |
212 | .B ENOSPC | |
357cf3fe | 213 | All possible shared memory IDs have been taken |
fea681da MK |
214 | .RB ( SHMMNI ), |
215 | or allocating a segment of the requested | |
216 | .I size | |
217 | would cause the system to exceed the system-wide limit on shared memory | |
218 | .RB ( SHMALL ). | |
eb57338f MK |
219 | .TP |
220 | .B EPERM | |
221 | The | |
222 | .B SHM_HUGETLB | |
223 | flag was specified, but the caller was not privileged (did not have the | |
224 | .B CAP_IPC_LOCK | |
225 | capability). | |
a1d5f77c MK |
226 | .SH "CONFORMING TO" |
227 | SVr4, POSIX.1-2001. | |
228 | .\" SVr4 documents an additional error condition EEXIST. | |
229 | ||
230 | .B SHM_HUGETLB | |
231 | is a non-portable Linux extension. | |
fea681da MK |
232 | .SH NOTES |
233 | .B IPC_PRIVATE | |
234 | isn't a flag field but a | |
c952e226 | 235 | .I key_t |
fea681da MK |
236 | type. |
237 | If this special value is used for | |
238 | .IR key , | |
c952e226 | 239 | the system call ignores everything but the least significant 9 bits of |
fea681da MK |
240 | .I shmflg |
241 | and creates a new shared memory segment (on success). | |
242 | .PP | |
540036b2 | 243 | The following limits on shared memory segment resources affect the |
c952e226 | 244 | .BR shmget () |
fea681da MK |
245 | call: |
246 | .TP 11 | |
247 | .B SHMALL | |
c952e226 MK |
248 | System wide maximum of shared memory pages |
249 | (on Linux, this limit can be read and modified via | |
250 | .IR /proc/sys/kernel/shmall ). | |
fea681da MK |
251 | .TP |
252 | .B SHMMAX | |
c952e226 MK |
253 | Maximum size in bytes for a shared memory segment: policy dependent |
254 | (on Linux, this limit can be read and modified via | |
255 | .IR /proc/sys/kernel/shmmax ). | |
fea681da MK |
256 | .TP |
257 | .B SHMMIN | |
258 | Minimum size in bytes for a shared memory segment: implementation | |
259 | dependent (currently 1 byte, though | |
260 | .B PAGE_SIZE | |
261 | is the effective minimum size). | |
262 | .TP | |
263 | .B SHMMNI | |
264 | System wide maximum number of shared memory segments: implementation | |
c952e226 MK |
265 | dependent (currently 4096, was 128 before Linux 2.3.99; |
266 | on Linux, this limit can be read and modified via | |
267 | .IR /proc/sys/kernel/shmmni ). | |
ed978af2 | 268 | .\" Kernels between 2.4.x and 2.6.8 had an off-by-one error that meant |
cd31a0d6 | 269 | .\" that we could create one more segment than SHMMNI -- MTK |
c952e226 | 270 | .\" This /proc file is not available in Linux 2.2 and earlier -- MTK |
fea681da MK |
271 | .PP |
272 | The implementation has no specific limits for the per process maximum | |
273 | number of shared memory segments | |
274 | .RB ( SHMSEG ). | |
4fb31341 MK |
275 | .SS Linux Notes |
276 | Until version 2.3.30 Linux would return EIDRM for a | |
277 | .BR shmget () | |
278 | on a shared memory segment scheduled for deletion. | |
fea681da MK |
279 | .SH BUGS |
280 | The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW | |
281 | would more clearly show its function. | |
fea681da MK |
282 | .SH "SEE ALSO" |
283 | .BR shmat (2), | |
284 | .BR shmctl (2), | |
285 | .BR shmdt (2), | |
286 | .BR ftok (3), | |
92243659 | 287 | .BR capabilities (7), |
2c5e151c | 288 | .BR svipc (7) |