Upgrade less(1). 1/2
[dragonfly.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: src/lib/libc/sys/semget.2,v 1.7.2.5 2001/12/14 18:34:01 ru Exp $
27 .\"
28 .Dd January 4, 2014
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/types.h
38 .In sys/ipc.h
39 .In sys/sem.h
40 .Ft int
41 .Fn semget "key_t key" "int nsems" "int flag"
42 .Sh DESCRIPTION
43 Based on the values of
44 .Fa key
45 and
46 .Fa flag ,
47 .Fn semget
48 returns the identifier of a newly created or previously existing
49 set of semaphores.
50 .\"
51 .\" This is copied verbatim from the shmget manpage.  Perhaps
52 .\" it should go in a common manpage, such as .Xr ipc 2
53 .\"
54 The key
55 is analogous to a filename: it provides a handle that names an
56 IPC object.
57 There are three ways to specify a key:
58 .Bl -bullet
59 .It
60 .Dv IPC_PRIVATE
61 may be specified, in which case a new IPC object will be created.
62 .It
63 An integer constant may be specified.
64 If no IPC object corresponding to
65 .Fa key
66 is specified and the
67 .Dv IPC_CREAT
68 bit is set in
69 .Fa flag ,
70 a new one will be created.
71 .It
72 .Fn ftok
73 may be used to generate a key from a pathname.
74 See
75 .Xr ftok 3 .
76 .El
77 .\"
78 .\" Likewise for this section, except SHM_* becomes SEM_*.
79 .\"
80 .Pp
81 The mode of a newly created IPC object is determined by
82 .Em OR Ns 'ing
83 the following constants into the
84 .Fa flag
85 parameter:
86 .Bl -tag -width XSEM_WXX6XXX
87 .It Dv SEM_R
88 Read access for user.
89 .It Dv SEM_A
90 Alter access for user.
91 .It Dv ( SEM_R>>3 )
92 Read access for group.
93 .It Dv ( SEM_A>>3 )
94 Alter access for group.
95 .It Dv ( SEM_R>>6 )
96 Read access for other.
97 .It Dv ( SEM_A>>6 )
98 Alter access for other.
99 .El
100 .Pp
101 If a new set of semaphores is being created,
102 .Fa nsems
103 is used to indicate the number of semaphores the set should contain.
104 Otherwise,
105 .Fa nsems
106 may be specified as 0.
107 .Sh RETURN VALUES
108 .Fn Semget
109 returns the id of a semaphore set if successful; otherwise, -1
110 is returned and
111 .Va errno
112 is set to indicate the error.
113 .Sh ENVIRONMENT
114 The XSI Interprocess Communication family of functions is also available
115 as an implementation in userspace.
116 To use it, the
117 .Xr sysvipcd 8
118 daemon has to be running.
119 .Pp
120 If the
121 .Ev USR_SYSVIPC
122 variable is set in a process' environment, the process and its children
123 will use the userspace implementation.
124 .Sh ERRORS
125 .Fn Semget
126 will fail if:
127 .Bl -tag -width Er
128 .\" ipcperm could fail (we're opening to read and write, as it were)
129 .It Bq Er EACCES
130 Access permission failure.
131 .\"
132 .\" sysv_sem.c is quite explicit about these, so I'm pretty sure
133 .\" this is accurate
134 .\"
135 .It Bq Er EEXIST
136 .Dv IPC_CREAT
137 and
138 .Dv IPC_EXCL
139 were specified, and a semaphore set corresponding to
140 .Fa key
141 already exists.
142 .It Bq Er EINVAL
143 The number of semaphores requested exceeds the system imposed maximum
144 per set.
145 .It Bq Er ENOSPC
146 Insufficiently many semaphores are available.
147 .It Bq Er ENOSPC
148 The kernel could not allocate a
149 .Fa "struct semid_ds" .
150 .It Bq Er ENOENT
151 No semaphore set was found corresponding to
152 .Fa key ,
153 and
154 .Dv IPC_CREAT
155 was not specified.
156 .El
157 .Sh SEE ALSO
158 .Xr semctl 2 ,
159 .Xr semop 2 ,
160 .Xr ftok 3