]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - lib/libc/sys/semget.2
MFC r330409:
[FreeBSD/stable/10.git] / lib / libc / sys / semget.2
1 .\"
2 .\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
3 .\"
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 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd March 4, 2018
29 .Dt SEMGET 2
30 .Os
31 .Sh NAME
32 .Nm semget
33 .Nd obtain a semaphore id
34 .Sh LIBRARY
35 .Lb libc
36 .Sh SYNOPSIS
37 .In sys/sem.h
38 .Ft int
39 .Fn semget "key_t key" "int nsems" "int flag"
40 .Sh DESCRIPTION
41 Based on the values of
42 .Fa key
43 and
44 .Fa flag ,
45 .Fn semget
46 returns the identifier of a newly created or previously existing
47 set of semaphores.
48 .\"
49 .\" This is copied verbatim from the shmget manpage.  Perhaps
50 .\" it should go in a common manpage, such as .Xr ipc 2
51 .\"
52 The key
53 is analogous to a filename: it provides a handle that names an
54 IPC object.
55 There are three ways to specify a key:
56 .Bl -bullet
57 .It
58 IPC_PRIVATE may be specified, in which case a new IPC object
59 will be created.
60 .It
61 An integer constant may be specified.
62 If no IPC object corresponding
63 to
64 .Fa key
65 is specified and the IPC_CREAT bit is set in
66 .Fa flag ,
67 a new one will be created.
68 .It
69 The
70 .Xr ftok 3
71 function
72 may be used to generate a key from a pathname.
73 .El
74 .\"
75 .\" Likewise for this section, except SHM_* becomes SEM_*.
76 .\"
77 .Pp
78 The mode of a newly created IPC object is determined by ORing these constants
79 into the
80 .Fa flag
81 argument:
82 .Bl -tag -width 0000
83 .It Dv 0400
84 Read access for user.
85 .It Dv 0200
86 Alter access for user.
87 .It Dv 0040
88 Read access for group.
89 .It Dv 0020
90 Alter access for group.
91 .It Dv 0004
92 Read access for other.
93 .It Dv 0002
94 Alter access for other.
95 .El
96 .Pp
97 If a new set of semaphores is being created,
98 .Fa nsems
99 is used to indicate the number of semaphores the set should contain.
100 Otherwise,
101 .Fa nsems
102 may be specified as 0.
103 .Sh RETURN VALUES
104 The
105 .Fn semget
106 system call
107 returns the id of a semaphore set if successful; otherwise, -1
108 is returned and
109 .Va errno
110 is set to indicate the error.
111 .Sh ERRORS
112 The
113 .Fn semget
114 system call
115 will fail if:
116 .Bl -tag -width Er
117 .\" ipcperm could fail (we are opening to read and write, as it were)
118 .It Bq Er EACCES
119 Access permission failure.
120 .\"
121 .\" sysv_sem.c is quite explicit about these, so I'm pretty sure
122 .\" this is accurate
123 .\"
124 .It Bq Er EEXIST
125 IPC_CREAT and IPC_EXCL were specified, and a semaphore set
126 corresponding to
127 .Fa key
128 already exists.
129 .It Bq Er EINVAL
130 The number of semaphores requested exceeds the system imposed maximum
131 per set.
132 .It Bq Er EINVAL
133 A semaphore set corresponding to
134 .Fa key
135 already exists and contains fewer semaphores than
136 .Fa nsems .
137 .It Bq Er EINVAL
138 A semaphore set corresponding to
139 .Fa key
140 does not exist and
141 .Fa nsems
142 is 0 or negative.
143 .It Bq Er ENOSPC
144 Insufficiently many semaphores are available.
145 .It Bq Er ENOSPC
146 The kernel could not allocate a
147 .Fa "struct semid_ds" .
148 .It Bq Er ENOENT
149 No semaphore set was found corresponding to
150 .Fa key ,
151 and IPC_CREAT was not specified.
152 .El
153 .Sh SEE ALSO
154 .Xr semctl 2 ,
155 .Xr semop 2 ,
156 .Xr ftok 3