]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/semget.2
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / man / man2 / semget.2
CommitLineData
55e303ae
A
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.14 2002/12/19 09:40:25 ru Exp $
27.\"
28.Dd September 12, 1995
29.Dt SEMGET 2
30.Os
31.Sh NAME
32.Nm semget
33.Nd obtain a semaphore id
55e303ae
A
34.Sh SYNOPSIS
35.In sys/types.h
36.In sys/ipc.h
37.In sys/sem.h
38.Ft int
39.Fn semget "key_t key" "int nsems" "int flag"
40.Sh DESCRIPTION
41Based on the values of
42.Fa key
43and
44.Fa flag ,
45.Fn semget
46returns the identifier of a newly created or previously existing
47set 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.\"
52The key
53is analogous to a filename: it provides a handle that names an
54IPC object. There are three ways to specify a key:
55.Bl -bullet
56.It
57IPC_PRIVATE may be specified, in which case a new IPC object
58will be created.
59.It
60An integer constant may be specified. If no IPC object corresponding
61to
62.Fa key
63is specified and the IPC_CREAT bit is set in
64.Fa flag ,
65a new one will be created.
66.It
67The
68.Xr ftok 3
69function
70may be used to generate a key from a pathname.
71.El
72.\"
73.\" Likewise for this section, except SHM_* becomes SEM_*.
74.\"
75.Pp
76The mode of a newly created IPC object is determined by
77.Em OR Ns 'ing
78the following constants into the
79.Fa flag
80argument:
81.Bl -tag -width XSEM_WXX6XXX
82.It Dv SEM_R
83Read access for user.
84.It Dv SEM_A
85Alter access for user.
86.It Dv ( SEM_R>>3 )
87Read access for group.
88.It Dv ( SEM_A>>3 )
89Alter access for group.
90.It Dv ( SEM_R>>6 )
91Read access for other.
92.It Dv ( SEM_A>>6 )
93Alter access for other.
94.El
95.Pp
96If a new set of semaphores is being created,
97.Fa nsems
98is used to indicate the number of semaphores the set should contain.
99Otherwise,
100.Fa nsems
101may be specified as 0.
102.Sh RETURN VALUES
103The
104.Fn semget
105system call
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
111The
112.Fn semget
113system call
114will fail if:
115.Bl -tag -width Er
116.\" ipcperm could fail (we're opening to read and write, as it were)
117.It Bq Er EACCES
118Access permission failure.
119.\"
120.\" sysv_sem.c is quite explicit about these, so I'm pretty sure
121.\" this is accurate
122.\"
123.It Bq Er EEXIST
124IPC_CREAT and IPC_EXCL were specified, and a semaphore set
125corresponding to
126.Fa key
127already exists.
128.It Bq Er EINVAL
129The number of semaphores requested exceeds the system imposed maximum
130per set.
131.It Bq Er ENOSPC
132Insufficiently many semaphores are available.
133.It Bq Er ENOSPC
134The kernel could not allocate a
135.Fa "struct semid_ds" .
136.It Bq Er ENOENT
137No semaphore set was found corresponding to
138.Fa key ,
139and IPC_CREAT was not specified.
140.El
141.Sh SEE ALSO
142.Xr semctl 2 ,
143.Xr semop 2 ,
144.Xr ftok 3