* Use id(1) instead of grep(1) to detect the presence of the smmsp
[dragonfly.git] / lib / libcr / 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 .\" $DragonFly: src/lib/libcr/sys/Attic/semget.2,v 1.2 2003/06/17 04:26:47 dillon Exp $
28 .\"
29 .Dd September 12, 1995
30 .Dt SEMGET 2
31 .Os
32 .Sh NAME
33 .Nm semget
34 .Nd obtain a semaphore id
35 .Sh LIBRARY
36 .Lb libc
37 .Sh SYNOPSIS
38 .In sys/types.h
39 .In sys/ipc.h
40 .In sys/sem.h
41 .Ft int
42 .Fn semget "key_t key" "int nsems" "int flag"
43 .Sh DESCRIPTION
44 Based on the values of
45 .Fa key
46 and
47 .Fa flag ,
48 .Fn semget
49 returns the identifier of a newly created or previously existing
50 set of semaphores.
51 .\"
52 .\" This is copied verbatim from the shmget manpage.  Perhaps
53 .\" it should go in a common manpage, such as .Xr ipc 2
54 .\"
55 The key
56 is analogous to a filename: it provides a handle that names an
57 IPC object.  There are three ways to specify a key:
58 .Bl -bullet
59 .It
60 IPC_PRIVATE may be specified, in which case a new IPC object
61 will be created.
62 .It
63 An integer constant may be specified.  If no IPC object corresponding
64 to
65 .Fa key
66 is specified and the IPC_CREAT bit is set in
67 .Fa flag ,
68 a new one will be created.
69 .It
70 .Fn ftok
71 may be used to generate a key from a pathname.  See
72 .Xr ftok 3 .
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
79 .Em OR Ns 'ing
80 the following constants into the
81 .Fa flag
82 parameter:
83 .Bl -tag -width XSEM_WXX6XXX
84 .It Dv SEM_R
85 Read access for user.
86 .It Dv SEM_A
87 Alter access for user.
88 .It Dv ( SEM_R>>3 )
89 Read access for group.
90 .It Dv ( SEM_A>>3 )
91 Alter access for group.
92 .It Dv ( SEM_R>>6 )
93 Read access for other.
94 .It Dv ( SEM_A>>6 )
95 Alter access for other.
96 .El
97 .Pp
98 If a new set of semaphores is being created,
99 .Fa nsems
100 is used to indicate the number of semaphores the set should contain.
101 Otherwise,
102 .Fa nsems
103 may be specified as 0.
104 .Sh RETURN VALUES
105 .Fn Semget
106 returns the id of a semaphore set if successful; otherwise, -1
107 is returned and
108 .Va errno
109 is set to indicate the error.
110 .Sh ERRORS
111 .Fn Semget
112 will fail if:
113 .Bl -tag -width Er
114 .\" ipcperm could fail (we're opening to read and write, as it were)
115 .It Bq Er EACCES
116 Access permission failure.
117 .\"
118 .\" sysv_sem.c is quite explicit about these, so I'm pretty sure
119 .\" this is accurate
120 .\"
121 .It Bq Er EEXIST
122 IPC_CREAT and IPC_EXCL were specified, and a semaphore set
123 corresponding to
124 .Fa key
125 already exists.
126 .It Bq Er EINVAL
127 The number of semaphores requested exceeds the system imposed maximum
128 per set.
129 .It Bq Er ENOSPC
130 Insufficiently many semaphores are available.
131 .It Bq Er ENOSPC
132 The kernel could not allocate a
133 .Fa "struct semid_ds" .
134 .It Bq Er ENOENT
135 No semaphore set was found corresponding to
136 .Fa key ,
137 and IPC_CREAT was not specified.
138 .El
139 .Sh SEE ALSO
140 .Xr semctl 2 ,
141 .Xr semop 2 ,
142 .Xr ftok 3