xref: /openbsd/lib/libc/sys/semget.2 (revision 09467b48)
1.\"	$OpenBSD: semget.2,v 1.19 2014/11/15 22:19:53 guenther 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 $Mdocdate: November 15 2014 $
34.Dt SEMGET 2
35.Os
36.Sh NAME
37.Nm semget
38.Nd get semaphore set
39.Sh SYNOPSIS
40.In sys/sem.h
41.Ft int
42.Fn semget "key_t key" "int nsems" "int semflg"
43.Sh DESCRIPTION
44The
45.Fn semget
46system call returns the semaphore identifier associated with
47.Fa key .
48.Pp
49A new set containing
50.Fa nsems
51semaphores is created if either
52.Fa key
53is equal to
54.Dv IPC_PRIVATE ,
55or
56.Fa key
57does not have a semaphore set associated with it and the
58.Dv IPC_CREAT
59bit is set in
60.Fa semflg .
61.Pp
62The access modes of the created semaphores is specified in
63.Fa semflg
64as a bitwise OR of zero or more of the following values:
65.Bd -literal -offset indent
66SEM_A        alter permission for owner
67SEM_R        read permission for owner
68
69SEM_A >> 3   alter permission for group
70SEM_R >> 3   read permission for group
71
72SEM_A >> 6   alter permission for other
73SEM_R >> 6   read permission for other
74.Ed
75.Pp
76If a new set of semaphores is created, the data structure associated with it
77(the
78.Va semid_ds
79structure, see
80.Xr semctl 2 )
81is initialized as follows:
82.Bl -bullet
83.It
84.Va sem_perm.cuid
85and
86.Va sem_perm.uid
87are set to the effective UID of the calling process.
88.It
89.Va sem_perm.gid
90and
91.Va sem_perm.cgid
92are set to the effective GID of the calling process.
93.It
94.Va sem_perm.mode
95is set to the lower 9 bits of
96.Fa semflg .
97.It
98.Va sem_nsems
99is set to the value of
100.Fa nsems .
101.It
102.Va sem_ctime
103is set to the current time.
104.It
105.Va sem_otime
106is set to 0.
107.El
108.Sh RETURN VALUES
109.Fn semget
110returns a non-negative semaphore identifier if successful.
111Otherwise, \-1 is returned and
112.Va errno
113is set to reflect the error.
114.Sh ERRORS
115.Bl -tag -width Er
116.It Bq Er EACCES
117The caller has no permission to access a semaphore set already associated with
118.Fa key .
119.It Bq Er EEXIST
120Both
121.Dv IPC_CREAT
122and
123.Dv IPC_EXCL
124are set in
125.Fa semflg ,
126and a semaphore set is already associated with
127.Fa key .
128.It Bq Er EINVAL
129.Va nsems
130is less than or equal to 0 or greater than the system limit for the
131number in a semaphore set.
132.Pp
133A semaphore set associated with
134.Fa key
135exists, but has fewer semaphores than the number specified in
136.Fa nsems .
137.It Bq Er ENOSPC
138A new set of semaphores could not be created because the system limit
139for the number of semaphores or the number of semaphore sets has been
140reached.
141.It Bq Er ENOENT
142.Dv IPC_CREAT
143was not set in
144.Fa semflg
145and no semaphore set associated with
146.Fa key
147was found.
148.El
149.Sh SEE ALSO
150.Xr semctl 2 ,
151.Xr semop 2 ,
152.Xr ftok 3
153