summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys/semget.2
blob: f8175a425ec887f853ccc7d078126af2b93a0013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
.\"
.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
.\"
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd September 12, 1995
.Dt SEMGET 2
.Os FreeBSD
.Sh NAME
.Nm semget
.Nd obtain a semaphore id
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <sys/ipc.h>
.Fd #include <sys/sem.h>
.Ft int
.Fn semget "key_t key" "int nsems" "int flag"
.Sh DESCRIPTION
Based on the values of
.Fa key
and
.Fa flag ,
.Fn semget
returns the identifier of a newly created or previously existing
set of semaphores.
.\"
.\" This is copied verbatim from the shmget manpage.  Perhaps
.\" it should go in a common manpage, such as .Xr ipc 2
.\"
The key
is analogous to a filename: it provides a handle that names an
IPC object.  There are three ways to specify a key:
.Bl -bullet
.It
IPC_PRIVATE may be specified, in which case a new IPC object
will be created.
.It
An integer constant may be specified.  If no IPC object corresponding
to
.Fa key
is specified and the IPC_CREAT bit is set in
.Fa flag ,
a new one will be created.
.It
.Fn ftok
may be used to generate a key from a pathname.  See
.Xr ftok 3 .
.El
.\"
.\" Likewise for this section, except SHM_* becomes SEM_*.
.\"
.Pp
The mode of a newly created IPC object is determined by
.Em OR Ns 'ing
the following constants into the
.Fa flag
parameter:
.Bl -tag -width XSEM_WXX6XXX
.It Dv SEM_R
Read access for user.
.It Dv SEM_A
Alter access for user.
.It Dv (SEM_R>>3)
Read access for group.
.It Dv (SEM_A>>3)
Alter access for group.
.It Dv (SEM_R>>6)
Read access for other.
.It Dv (SEM_A>>6)
Alter access for other.
.El
.Pp
If a new set of semaphores is being created,
.Fa nsems
is used to indicate the number of semaphores the set should contain.
Otherwise,
.Fa nsems
may be specified as 0.
.Sh RETURN VALUES
.Fn Semget
returns the id of a semaphore set if successful; otherwise, -1
is returned and
.Va errno
is set to indicate the error.
.Sh ERRORS
.Fn Semget
will fail if:
.Bl -tag -width Er
.\" ipcperm could fail (we're opening to read and write, as it were)
.It Bq Er EACCES
Access permission failure.
.\"
.\" sysv_sem.c is quite explicit about these, so I'm pretty sure
.\" this is accurate
.\"
.It Bq Er EEXIST
IPC_CREAT and IPC_EXCL were specified, and a semaphore set
corresponding to
.Fa key
already exists.
.It Bq Er EINVAL
The number of semaphores requested exceeds the system imposed maximum
per set.
.It Bq Er ENOSPC
Insufficiently many semaphores are available.
.It Bq Er ENOSPC
The kernel could not allocate a
.Fa "struct semid_ds" .
.It Bq Er ENOENT
No semaphore set was found corresponding to
.Fa key ,
and IPC_CREAT was not specified.
.Sh SEE ALSO
.Xr semctl 2 ,
.Xr semop 2 ,
.Xr ftok 3
OpenPOWER on IntegriCloud