]>
Commit | Line | Data |
---|---|---|
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 | |
34 | .Sh LIBRARY | |
35 | .Lb libc | |
36 | .Sh SYNOPSIS | |
37 | .In sys/types.h | |
38 | .In sys/ipc.h | |
39 | .In sys/sem.h | |
40 | .Ft int | |
41 | .Fn semget "key_t key" "int nsems" "int flag" | |
42 | .Sh DESCRIPTION | |
43 | Based on the values of | |
44 | .Fa key | |
45 | and | |
46 | .Fa flag , | |
47 | .Fn semget | |
48 | returns the identifier of a newly created or previously existing | |
49 | set 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 | .\" | |
54 | The key | |
55 | is analogous to a filename: it provides a handle that names an | |
56 | IPC object. There are three ways to specify a key: | |
57 | .Bl -bullet | |
58 | .It | |
59 | IPC_PRIVATE may be specified, in which case a new IPC object | |
60 | will be created. | |
61 | .It | |
62 | An integer constant may be specified. If no IPC object corresponding | |
63 | to | |
64 | .Fa key | |
65 | is specified and the IPC_CREAT bit is set in | |
66 | .Fa flag , | |
67 | a new one will be created. | |
68 | .It | |
69 | The | |
70 | .Xr ftok 3 | |
71 | function | |
72 | may be used to generate a key from a pathname. | |
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 | argument: | |
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 | The | |
106 | .Fn semget | |
107 | system call | |
108 | returns the id of a semaphore set if successful; otherwise, -1 | |
109 | is returned and | |
110 | .Va errno | |
111 | is set to indicate the error. | |
112 | .Sh ERRORS | |
113 | The | |
114 | .Fn semget | |
115 | system call | |
116 | will fail if: | |
117 | .Bl -tag -width Er | |
118 | .\" ipcperm could fail (we're opening to read and write, as it were) | |
119 | .It Bq Er EACCES | |
120 | Access permission failure. | |
121 | .\" | |
122 | .\" sysv_sem.c is quite explicit about these, so I'm pretty sure | |
123 | .\" this is accurate | |
124 | .\" | |
125 | .It Bq Er EEXIST | |
126 | IPC_CREAT and IPC_EXCL were specified, and a semaphore set | |
127 | corresponding to | |
128 | .Fa key | |
129 | already exists. | |
130 | .It Bq Er EINVAL | |
131 | The number of semaphores requested exceeds the system imposed maximum | |
132 | per set. | |
133 | .It Bq Er ENOSPC | |
134 | Insufficiently many semaphores are available. | |
135 | .It Bq Er ENOSPC | |
136 | The kernel could not allocate a | |
137 | .Fa "struct semid_ds" . | |
138 | .It Bq Er ENOENT | |
139 | No semaphore set was found corresponding to | |
140 | .Fa key , | |
141 | and IPC_CREAT was not specified. | |
142 | .El | |
143 | .Sh SEE ALSO | |
144 | .Xr semctl 2 , | |
145 | .Xr semop 2 , | |
146 | .Xr ftok 3 |