]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/semget.2
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.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 September 12, 1995
29 .Dt SEMGET 2
30 .Os FreeBSD
31 .Sh NAME
32 .Nm semget
33 .Nd obtain a semaphore id
34 .Sh SYNOPSIS
35 .Fd #include <sys/types.h>
36 .Fd #include <sys/ipc.h>
37 .Fd #include <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.  There are three ways to specify a key:
55 .Bl -bullet
56 .It
57 IPC_PRIVATE may be specified, in which case a new IPC object
58 will be created.
59 .It
60 An integer constant may be specified.  If no IPC object corresponding
61 to
62 .Fa key
63 is specified and the IPC_CREAT bit is set in
64 .Fa flag ,
65 a new one will be created.
66 .It
67 .Fn ftok
68 may be used to generate a key from a pathname.  See
69 .Xr ftok 3 .
70 .El
71 .\"
72 .\" Likewise for this section, except SHM_* becomes SEM_*.
73 .\"
74 .Pp
75 The mode of a newly created IPC object is determined by
76 .Em OR Ns 'ing
77 the following constants into the
78 .Fa flag
79 parameter:
80 .Bl -tag -width XSEM_WXX6XXX
81 .It Dv SEM_R
82 Read access for user.
83 .It Dv SEM_A
84 Alter access for user.
85 .It Dv (SEM_R>>3)
86 Read access for group.
87 .It Dv (SEM_A>>3)
88 Alter access for group.
89 .It Dv (SEM_R>>6)
90 Read access for other.
91 .It Dv (SEM_A>>6)
92 Alter access for other.
93 .El
94 .Pp
95 If a new set of semaphores is being created,
96 .Fa nsems
97 is used to indicate the number of semaphores the set should contain.
98 Otherwise,
99 .Fa nsems
100 may be specified as 0.
101 .Sh RETURN VALUES
102 .Fn Semget
103 returns the id of a semaphore set if successful; otherwise, -1
104 is returned and
105 .Va errno
106 is set to indicate the error.
107 .Sh ERRORS
108 .Fn Semget
109 will fail if:
110 .Bl -tag -width Er
111 .\" ipcperm could fail (we're opening to read and write, as it were)
112 .It Bq Er EACCES
113 Access permission failure.
114 .\"
115 .\" sysv_sem.c is quite explicit about these, so I'm pretty sure
116 .\" this is accurate
117 .\"
118 .It Bq Er EEXIST
119 IPC_CREAT and IPC_EXCL were specified, and a semaphore set
120 corresponding to
121 .Fa key
122 already exists.
123 .It Bq Er EINVAL
124 The number of semaphores requested exceeds the system imposed maximum
125 per set.
126 .It Bq Er ENOSPC
127 Insufficiently many semaphores are available.
128 .It Bq Er ENOSPC
129 The kernel could not allocate a
130 .Fa "struct semid_ds" .
131 .It Bq Er ENOENT
132 No semaphore set was found corresponding to
133 .Fa key ,
134 and IPC_CREAT was not specified.
135 .Sh SEE ALSO
136 .Xr semctl 2 ,
137 .Xr semop 2 ,
138 .Xr ftok 3