xref: /dragonfly/lib/libc/sys/semget.2 (revision 6e285212)
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/libc/sys/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
44Based on the values of
45.Fa key
46and
47.Fa flag ,
48.Fn semget
49returns the identifier of a newly created or previously existing
50set 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.\"
55The key
56is analogous to a filename: it provides a handle that names an
57IPC object.  There are three ways to specify a key:
58.Bl -bullet
59.It
60IPC_PRIVATE may be specified, in which case a new IPC object
61will be created.
62.It
63An integer constant may be specified.  If no IPC object corresponding
64to
65.Fa key
66is specified and the IPC_CREAT bit is set in
67.Fa flag ,
68a new one will be created.
69.It
70.Fn ftok
71may 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
78The mode of a newly created IPC object is determined by
79.Em OR Ns 'ing
80the following constants into the
81.Fa flag
82parameter:
83.Bl -tag -width XSEM_WXX6XXX
84.It Dv SEM_R
85Read access for user.
86.It Dv SEM_A
87Alter access for user.
88.It Dv ( SEM_R>>3 )
89Read access for group.
90.It Dv ( SEM_A>>3 )
91Alter access for group.
92.It Dv ( SEM_R>>6 )
93Read access for other.
94.It Dv ( SEM_A>>6 )
95Alter access for other.
96.El
97.Pp
98If a new set of semaphores is being created,
99.Fa nsems
100is used to indicate the number of semaphores the set should contain.
101Otherwise,
102.Fa nsems
103may be specified as 0.
104.Sh RETURN VALUES
105.Fn Semget
106returns the id of a semaphore set if successful; otherwise, -1
107is returned and
108.Va errno
109is set to indicate the error.
110.Sh ERRORS
111.Fn Semget
112will 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
116Access 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
122IPC_CREAT and IPC_EXCL were specified, and a semaphore set
123corresponding to
124.Fa key
125already exists.
126.It Bq Er EINVAL
127The number of semaphores requested exceeds the system imposed maximum
128per set.
129.It Bq Er ENOSPC
130Insufficiently many semaphores are available.
131.It Bq Er ENOSPC
132The kernel could not allocate a
133.Fa "struct semid_ds" .
134.It Bq Er ENOENT
135No semaphore set was found corresponding to
136.Fa key ,
137and IPC_CREAT was not specified.
138.El
139.Sh SEE ALSO
140.Xr semctl 2 ,
141.Xr semop 2 ,
142.Xr ftok 3
143