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 Tue Oct 22 17:54:56 1996 by Eric S. Raymond <esr@thyrsus.com>
24 .\" Modified 1 Jan 2002, Martin Schulze <joey@infodrom.org>
25 .\" Modified 4 Jan 2002, Michael Kerrisk <mtk-manpages@gmx.net>
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk-manpages@gmx.net>
27 .\" Added notes on capability requirements
28 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk-manpages@gmx.net>
29 .\" Language and formatting clean-ups
30 .\" Added notes on /proc files
31 .\" Rewrote BUGS note about semget()'s failure to initialise
34 .TH SEMGET 2 2004-05-27 "Linux 2.6.6" "Linux Programmer's Manual"
36 semget \- get a semaphore set identifier
40 #include <sys/types.h>
47 .BI "int semget(key_t " key ,
53 system call returns the semaphore set identifier
54 associated with the argument
58 semaphores is created if
62 or if no existing semaphore set is associated with
75 and a semaphore set already exists for
83 (This is analogous to the effect of the combination
88 Upon creation, the least significant 9 bits of the argument
90 define the permissions (for owner, group and others)
91 for the semaphore set.
92 These bits have the same format, and the same
97 (though the execute permissions are
98 not meaningful for semaphores, and write permissions mean permission
99 to alter semaphore values).
101 The values of the semaphores in a newly created set are indeterminate.
102 (POSIX.1-2001 is explicit on this point.)
103 Although Linux, like many other implementations,
104 initialises the semaphore values to 0,
105 a portable application cannot rely on this:
106 it should explicitly initialise the semaphores to the desired values.
107 .\" In truth, every one of the many implementations that I've tested sets
108 .\" the values to zero, but I suppose there is/was some obscure
109 .\" implementation out there that does not.
111 When creating a new semaphore set,
113 initialises the set's associated data structure,
122 are set to the effective user ID of the calling process.
127 are set to the effective group ID of the calling process.
129 The least significant 9 bits of
131 are set to the least significant 9 bits of
135 is set to the value of
142 is set to the current time.
148 when a semaphore set is not being created.
151 must be greater than 0
152 and less than or equal to the maximum number of semaphores per semaphore set
155 If the semaphore set already exists, the permissions are
157 .\" and a check is made to see if it is marked for destruction.
159 If successful, the return value will be the semaphore set identifier
160 (a nonnegative integer), otherwise \-1
163 indicating the error.
167 will be set to one of the following:
170 A semaphore set exists for
172 but the calling process does not have permission to access the set,
173 and does not have the
178 A semaphore set exists for
188 .\" The semaphore set is marked to be deleted.
192 is less than 0 or greater than the limit on the number
193 of semaphores per semaphore set
195 or a semaphore set corresponding to
199 is larger than the number of semaphores in that set.
202 No semaphore set exists for
210 A semaphore set has to be created but the system does not have
211 enough memory for the new data structure.
214 A semaphore set has to be created but the system limit for the maximum
215 number of semaphore sets
217 or the system wide maximum number of semaphores
222 isn't a flag field but a
225 If this special value is used for
227 the system call ignores everything but the least significant 9 bits of
229 and creates a new semaphore set (on success).
231 The following limits on semaphore set resources affect the
236 System wide maximum number of semaphore sets: policy dependent
237 (on Linux, this limit can be read and modified via the fourth field of
238 .IR /proc/sys/kernel/sem ).
239 .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
242 Maximum number of semaphores per semid: implementation dependent
243 (on Linux, this limit can be read and modified via the first field of
244 .IR /proc/sys/kernel/sem ).
247 System wide maximum number of semaphores: policy dependent
248 (on Linux, this limit can be read and modified via the second field of
249 .IR /proc/sys/kernel/sem ).
254 The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW
255 would more clearly show its function.
257 The semaphores in a set are not initialised by
259 .\" In fact they are initialised to zero on Linux, but POSIX.1-2001
260 .\" does not specify this, and we can't portably rely on it.
261 In order to initialise the semaphores,
263 must be used to perform a
267 operation on the semaphore set.
268 (Where multiple peers do not know who will be the first to
269 initialise the set, checking for a non-zero
271 in the associated data structure retrieved by a
274 operation can be used to avoid races.)
277 .\" SVr4 documents additional error conditions EFBIG, E2BIG, EAGAIN,
283 .BR capabilities (7),
284 .BR sem_overview (7),