import less(1)
[unleashed/tickless.git] / share / man / man2 / semget.2
blob73d35256bdb68ca398fdf14b427d544be7c70d66
1 '\" te
2 .\" Copyright (c) 2006, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH SEMGET 2 "Aug 14, 2006"
8 .SH NAME
9 semget \- get set of semaphores
10 .SH SYNOPSIS
11 .LP
12 .nf
13 #include <sys/types.h>
14 #include <sys/ipc.h>
15 #include <sys/sem.h>
17 \fBint\fR \fBsemget\fR(\fBkey_t\fR \fIkey\fR, \fBint\fR \fInsems\fR, \fBint\fR \fIsemflg\fR);
18 .fi
20 .SH DESCRIPTION
21 .sp
22 .LP
23 The \fBsemget()\fR function returns the semaphore identifier associated with
24 \fIkey\fR.
25 .sp
26 .LP
27 A semaphore identifier and associated data structure and set containing
28 \fInsems\fR semaphores (see \fBIntro\fR(2)) are created for \fIkey\fR if one of
29 the following is true:
30 .RS +4
31 .TP
32 .ie t \(bu
33 .el o
34 \fIkey\fR is equal to \fBIPC_PRIVATE\fR.
35 .RE
36 .RS +4
37 .TP
38 .ie t \(bu
39 .el o
40 \fIkey\fR does not already have a semaphore identifier associated with it, and
41 (\fIsemflg\fR\fB&IPC_CREAT\fR) is true.
42 .RE
43 .sp
44 .LP
45 On creation, the data structure associated with the new semaphore identifier is
46 initialized as follows:
47 .RS +4
48 .TP
49 .ie t \(bu
50 .el o
51 \fBsem_perm.cuid\fR, \fBsem_perm.uid\fR, \fBsem_perm.cgid\fR, and
52 \fBsem_perm.gid\fR are set equal to the effective user \fBID\fR and effective
53 group \fBID,\fR respectively, of the calling process.
54 .RE
55 .RS +4
56 .TP
57 .ie t \(bu
58 .el o
59 The access permission bits of \fBsem_perm.mode\fR are set equal to the access
60 permission bits of \fIsemflg\fR.
61 .RE
62 .RS +4
63 .TP
64 .ie t \(bu
65 .el o
66 \fBsem_nsems\fR is set equal to the value of \fInsems\fR.
67 .RE
68 .RS +4
69 .TP
70 .ie t \(bu
71 .el o
72 \fBsem_otime\fR is set equal to 0 and \fBsem_ctime\fR is set equal to the
73 current time.
74 .RE
75 .SH RETURN VALUES
76 .sp
77 .LP
78 Upon successful completion, a non-negative integer representing a semaphore
79 identifier is returned. Otherwise, \fB\(mi1\fR is returned and \fBerrno\fR is
80 set to indicate the error.
81 .SH ERRORS
82 .sp
83 .LP
84 The \fBsemget()\fR function will fail if:
85 .sp
86 .ne 2
87 .na
88 \fB\fBEACCES\fR\fR
89 .ad
90 .RS 10n
91 A semaphore identifier exists for \fIkey\fR, but operation permission (see
92 \fBIntro\fR(2)) as specified by the low-order 9 bits of \fIsemflg\fR would not
93 be granted.
94 .RE
96 .sp
97 .ne 2
98 .na
99 \fB\fBEEXIST\fR\fR
101 .RS 10n
102 A semaphore identifier exists for \fIkey\fR but both
103 (\fIsemflg\fR\fB&IPC_CREAT\fR) and (\fIsemflg\fR\fB&IPC_EXCL\fR) are both true.
107 .ne 2
109 \fB\fBEINVAL\fR\fR
111 .RS 10n
112 The \fInsems\fR argument is either less than or equal to 0 or greater than the
113 system-imposed limit. See NOTES.
115 A semaphore identifier exists for \fIkey\fR, but the number of semaphores in
116 the set associated with it is less than \fInsems\fR and \fInsems\fR is not
117 equal to 0.
121 .ne 2
123 \fB\fBENOENT\fR\fR
125 .RS 10n
126 A semaphore identifier does not exist for \fIkey\fR and
127 (\fIsemflg\fR\fB&IPC_CREAT\fR) is false.
131 .ne 2
133 \fB\fBENOSPC\fR\fR
135 .RS 10n
136 A semaphore identifier is to be created but the system-imposed limit on the
137 maximum number of allowed semaphores or semaphore identifiers system-wide would
138 be exceeded. See NOTES.
141 .SH ATTRIBUTES
144 See \fBattributes\fR(5) for descriptions of the following attributes:
149 box;
150 c | c
151 l | l .
152 ATTRIBUTE TYPE  ATTRIBUTE VALUE
154 Interface Stability     Standard
157 .SH SEE ALSO
160 \fBipcrm\fR(1), \fBipcs\fR(1), \fBrctladm\fR(1M), \fBIntro\fR(2),
161 \fBsemctl\fR(2), \fBsemop\fR(2), \fBsetrctl\fR(2), \fBftok\fR(3C),
162 \fBattributes\fR(5), \fBstandards\fR(5)
163 .SH NOTES
166 The system-imposed limit on the value of the \fInsems\fR argument is the
167 maintained on a per-process basis using the \fBprocess.max-sem-nsems\fR
168 resource control.
171 The system-imposed limit on the number of semaphore identifiers is maintained
172 on a per-project basis using the \fBproject.max-sem-ids\fR resource control.
173 The  \fBzone.max-sem-ids\fR resource control limis the total number of
174 semaphore identifiers that can be allocated by a zone.
177 See \fBrctladm\fR(1M) and \fBsetrctl\fR(2) for information about using resource
178 controls.