xref: /minix3/lib/libc/sys/semget.2 (revision 2fe8fb192fe7e8720e3e7a77f928da545e872a6a)
1.\"	$NetBSD: semget.2,v 1.18 2006/10/08 08:22:34 rillig Exp $
2.\"
3.\" Copyright (c) 1995 Frank van der Linden
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"      This product includes software developed for the NetBSD Project
17.\"      by Frank van der Linden
18.\" 4. The name of the author may not be used to endorse or promote products
19.\"    derived from this software without specific prior written permission
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31.\"
32.Dd May 13, 2004
33.Dt SEMGET 2
34.Os
35.Sh NAME
36.Nm semget
37.Nd get set of semaphores
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In sys/sem.h
42.Ft int
43.Fn semget "key_t key" "int nsems" "int semflg"
44.Sh DESCRIPTION
45The
46.Fn semget
47system call returns the semaphore identifier associated with
48.Fa key .
49.Pp
50A new set containing
51.Fa nsems
52semaphores is created if either
53.Fa key
54is equal to
55.Dv IPC_PRIVATE ,
56or
57.Fa key
58does not have a semaphore set associated with it and the
59.Dv IPC_CREAT
60bit is set in
61.Fa semflg .
62If both the
63.Dv IPC_CREAT
64bit and the
65.Dv IPC_EXCL
66bit are set in
67.Fa semflg ,
68and
69.Fa key
70has a semaphore set associated with it already,
71the operation will fail.
72.Pp
73If a new set of semaphores is created, the data structure associated with it
74(the
75.Va semid_ds
76structure, see
77.Xr semctl 2 )
78is initialized as follows:
79.Bl -bullet
80.It
81.Va sem_perm.cuid
82and
83.Va sem_perm.uid
84are set to the effective uid of the calling process.
85.It
86.Va sem_perm.gid
87and
88.Va sem_perm.cgid
89are set to the effective gid of the calling process.
90.It
91.Va sem_perm.mode
92is set to the lower 9 bits of
93.Fa semflg .
94.It
95.Va sem_nsems
96is set to the value of
97.Fa nsems .
98.It
99.Va sem_ctime
100is set to the current time.
101.It
102.Va sem_otime
103is set to 0.
104.El
105.Sh RETURN VALUES
106.Fn semget
107returns a non-negative semaphore identifier if successful.
108Otherwise, \-1 is returned and
109.Va errno
110is set to reflect the error.
111.Sh ERRORS
112.Bl -tag -width Er
113.It Bq Er EACCES
114The caller has no permission to access a semaphore set already associated with
115.Fa key .
116.It Bq Er EEXIST
117Both
118.Dv IPC_CREAT
119and
120.Dv IPC_EXCL
121are set in
122.Fa semflg ,
123and a semaphore set is already associated with
124.Fa key .
125.It Bq Er EINVAL
126.Va nsems
127is less than 0 or greater than the system limit for the number in a semaphore
128set.
129.Pp
130A semaphore set associated with
131.Fa key
132exists, but has fewer semaphores than the number specified in
133.Fa nsems .
134.It Bq Er ENOSPC
135A new set of semaphores could not be created because the system limit
136for the number of semaphores or the number of semaphore sets has been
137reached.
138.It Bq Er ENOENT
139.Dv IPC_CREAT
140is not set in
141.Fa semflg
142and no semaphore set associated with
143.Fa key
144was found.
145.El
146.Sh SEE ALSO
147.Xr ipcs 1 ,
148.Xr semctl 2 ,
149.Xr semop 2 ,
150.Xr ftok 3
151.Sh STANDARDS
152The
153.Nm
154system call conforms to
155.St -xsh5 .
156.Sh HISTORY
157Semaphores appeared in the first release of
158.At V .
159