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