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 When creating a new semaphore set,
103 initialises the set's associated data structure
112 are set to the effective user ID of the calling process.
117 are set to the effective group ID of the calling process.
119 The least significant 9 bits of
121 are set to the least significant 9 bits of
125 is set to the value of
132 is set to the current time.
138 when a semaphore set is not being created.
141 must be greater than 0
142 and less than or equal to the maximum number of semaphores per semaphore set
145 If the semaphore set already exists, the permissions are
147 .\" and a check is made to see if it is marked for destruction.
149 If successful, the return value will be the semaphore set identifier
150 (a nonnegative integer), otherwise \-1
153 indicating the error.
157 will be set to one of the following:
160 A semaphore set exists for
162 but the calling process does not have permission to access the set,
163 and does not have the
168 A semaphore set exists for
178 .\" The semaphore set is marked to be deleted.
182 is less than 0 or greater than the limit on the number
183 of semaphores per semaphore set
185 or a semaphore set corresponding to
189 is larger than the number of semaphores in that set.
192 No semaphore set exists for
200 A semaphore set has to be created but the system does not have
201 enough memory for the new data structure.
204 A semaphore set has to be created but the system limit for the maximum
205 number of semaphore sets
207 or the system wide maximum number of semaphores
212 isn't a flag field but a
215 If this special value is used for
217 the system call ignores everything but the least significant 9 bits of
219 and creates a new semaphore set (on success).
221 The following limits on semaphore set resources affect the
226 System wide maximum number of semaphore sets: policy dependent
227 (on Linux, this limit can be read and modified via the fourth field of
228 .IR /proc/sys/kernel/sem ).
229 .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
232 Maximum number of semaphores per semid: implementation dependent
233 (on Linux, this limit can be read and modified via the first field of
234 .IR /proc/sys/kernel/sem ).
237 System wide maximum number of semaphores: policy dependent
238 (on Linux, this limit can be read and modified via the second field of
239 .IR /proc/sys/kernel/sem ).
244 The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW
245 would more clearly show its function.
247 The semaphores in a set are not initialised by
249 .\" In fact they are initialised to zero on Linux, but POSIX.1-2001
250 .\" does not specify this, and we can't portably rely on it.
251 In order to initialise the semaphores,
253 must be used to perform a
257 operation on the semaphore set.
258 (Where multiple peers do not know who will be the first to
259 initialise the set, checking for a non-zero
261 in the associated data structure retrieved by a
264 operation can be used to avoid races.)
267 SVr4 documents additional error conditions EFBIG, E2BIG, EAGAIN,