1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
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 .\" Modified Tue Oct 22 17:54:56 1996 by Eric S. Raymond <esr@thyrsus.com>
26 .\" Modified 1 Jan 2002, Martin Schulze <joey@infodrom.org>
27 .\" Modified 4 Jan 2002, Michael Kerrisk <mtk.manpages@gmail.com>
28 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Added notes on capability requirements
30 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Language and formatting clean-ups
32 .\" Added notes on /proc files
33 .\" Rewrote BUGS note about semget()'s failure to initialize
36 .TH SEMGET 2 2012-05-31 "Linux" "Linux Programmer's Manual"
38 semget \- get a System V semaphore set identifier
41 .B #include <sys/types.h>
42 .B #include <sys/ipc.h>
43 .B #include <sys/sem.h>
46 .BI "int semget(key_t " key ,
52 system call returns the System V semaphore set identifier
53 associated with the argument
57 semaphores is created if
61 or if no existing semaphore set is associated with
74 and a semaphore set already exists for
82 (This is analogous to the effect of the combination
87 Upon creation, the least significant 9 bits of the argument
89 define the permissions (for owner, group and others)
90 for the semaphore set.
91 These bits have the same format, and the same
96 (though the execute permissions are
97 not meaningful for semaphores, and write permissions mean permission
98 to alter semaphore values).
100 The values of the semaphores in a newly created set are indeterminate.
101 (POSIX.1-2001 is explicit on this point.)
102 Although Linux, like many other implementations,
103 initializes the semaphore values to 0,
104 a portable application cannot rely on this:
105 it should explicitly initialize the semaphores to the desired values.
106 .\" In truth, every one of the many implementations that I've tested sets
107 .\" the values to zero, but I suppose there is/was some obscure
108 .\" implementation out there that does not.
110 When creating a new semaphore set,
112 initializes the set's associated data structure,
121 are set to the effective user ID of the calling process.
126 are set to the effective group ID of the calling process.
128 The least significant 9 bits of
130 are set to the least significant 9 bits of
134 is set to the value of
141 is set to the current time.
147 when a semaphore set is not being created.
150 must be greater than 0
151 and less than or equal to the maximum number of semaphores per semaphore set
154 If the semaphore set already exists, the permissions are
156 .\" and a check is made to see if it is marked for destruction.
158 If successful, the return value will be the semaphore set identifier
159 (a nonnegative integer), otherwise, \-1
162 indicating the error.
166 will be set to one of the following:
169 A semaphore set exists for
171 but the calling process does not have permission to access the set,
172 and does not have the
177 A semaphore set exists for
187 .\" The semaphore set is marked to be deleted.
191 is less than 0 or greater than the limit on the number
192 of semaphores per semaphore set
196 A semaphore set corresponding to
200 is larger than the number of semaphores in that set.
203 No semaphore set exists for
211 A semaphore set has to be created but the system does not have
212 enough memory for the new data structure.
215 A semaphore set has to be created but the system limit for the maximum
216 number of semaphore sets
218 or the system wide maximum number of semaphores
223 .\" SVr4 documents additional error conditions EFBIG, E2BIG, EAGAIN,
230 isn't required on Linux or by any version of POSIX.
232 some old implementations required the inclusion of these header files,
233 and the SVID also documented their inclusion.
234 Applications intended to be portable to such old systems may need
235 to include these header files.
236 .\" Like Linux, the FreeBSD man pages still document
237 .\" the inclusion of these header files.
240 isn't a flag field but a
243 If this special value is used for
245 the system call ignores everything but the least significant 9 bits of
247 and creates a new semaphore set (on success).
249 The following limits on semaphore set resources affect the
254 System wide maximum number of semaphore sets: policy dependent
255 (on Linux, this limit can be read and modified via the fourth field of
256 .IR /proc/sys/kernel/sem ).
257 .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
260 Maximum number of semaphores per semaphore ID: implementation dependent
261 (on Linux, this limit can be read and modified via the first field of
262 .IR /proc/sys/kernel/sem ).
265 System wide maximum number of semaphores: policy dependent
266 (on Linux, this limit can be read and modified via the second field of
267 .IR /proc/sys/kernel/sem ).
274 was perhaps unfortunate,
276 would more clearly show its function.
278 The semaphores in a set are not initialized by
280 .\" In fact they are initialized to zero on Linux, but POSIX.1-2001
281 .\" does not specify this, and we can't portably rely on it.
282 In order to initialize the semaphores,
284 must be used to perform a
288 operation on the semaphore set.
289 (Where multiple peers do not know who will be the first to
290 initialize the set, checking for a nonzero
292 in the associated data structure retrieved by a
295 operation can be used to avoid races.)
300 .BR capabilities (7),
301 .BR sem_overview (7),