]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/semget.2
xnu-6153.11.26.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 34.Sh SYNOPSIS
55e303ae
A
35.In sys/sem.h
36.Ft int
2d21ac55
A
37.Fo semget
38.Fa "key_t key"
39.Fa "int nsems"
40.Fa "int semflg"
41.Fc
55e303ae
A
42.Sh DESCRIPTION
43Based on the values of
44.Fa key
45and
2d21ac55 46.Fa semflg ,
55e303ae
A
47.Fn semget
48returns the identifier of a newly created or previously existing
49set of semaphores.
50.\"
51.\" This is copied verbatim from the shmget manpage. Perhaps
52.\" it should go in a common manpage, such as .Xr ipc 2
53.\"
54The key
55is analogous to a filename: it provides a handle that names an
56IPC object. There are three ways to specify a key:
57.Bl -bullet
58.It
59IPC_PRIVATE may be specified, in which case a new IPC object
60will be created.
61.It
62An integer constant may be specified. If no IPC object corresponding
63to
64.Fa key
65is specified and the IPC_CREAT bit is set in
2d21ac55 66.Fa semflg ,
55e303ae
A
67a new one will be created.
68.It
69The
70.Xr ftok 3
71function
72may be used to generate a key from a pathname.
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
2d21ac55 81.Fa semflg
55e303ae
A
82argument:
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
105The
106.Fn semget
107system call
108returns the id of a semaphore set if successful; otherwise, -1
109is returned and
110.Va errno
111is set to indicate the error.
112.Sh ERRORS
113The
114.Fn semget
115system call
116will fail if:
117.Bl -tag -width Er
2d21ac55 118.\" ===========
55e303ae
A
119.\" ipcperm could fail (we're opening to read and write, as it were)
120.It Bq Er EACCES
121Access permission failure.
2d21ac55 122.\" ===========
55e303ae 123.\"
2d21ac55
A
124.\" sysv_sem.c is quite explicit about these,
125.\" so I'm pretty sure this is accurate
55e303ae
A
126.\"
127.It Bq Er EEXIST
2d21ac55
A
128IPC_CREAT and IPC_EXCL were specified,
129and a semaphore set corresponding to
55e303ae
A
130.Fa key
131already exists.
2d21ac55
A
132.\" ===========
133.It Bq Er EINVAL
134The number of semaphores requested
135is either less than 1 or greater than the system imposed maximum per set.
136.\" ===========
55e303ae 137.It Bq Er EINVAL
2d21ac55
A
138A semaphore identifier exists for the argument key,
139but the number of semaphores in the set associated with it
140is less than
141.Fa nsems ,
142and
143.Fa nsems
144is non-zero.
145.\" ===========
146.It Bq Er ENOENT
147No semaphore set was found corresponding to
148.Fa key ,
149and IPC_CREAT was not specified.
150.\" ===========
55e303ae
A
151.It Bq Er ENOSPC
152Insufficiently many semaphores are available.
2d21ac55 153.\" ===========
55e303ae
A
154.It Bq Er ENOSPC
155The kernel could not allocate a
156.Fa "struct semid_ds" .
55e303ae 157.El
2d21ac55
A
158.Sh LEGACY SYNOPSIS
159.Fd #include <sys/types.h>
160.Fd #include <sys/ipc.h>
161.Fd #include <sys/sem.h>
162.Pp
163The include files
164.In sys/types.h
165and
166.In sys/ipc.h
167are necessary.
55e303ae
A
168.Sh SEE ALSO
169.Xr semctl 2 ,
170.Xr semop 2 ,
2d21ac55
A
171.Xr ftok 3 ,
172.Xr compat 5