]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 Giorgio Ciucci <giorgio@crcc.it> |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da | 4 | .\" Permission is granted to make and distribute verbatim copies of this |
f354abd0 | 5 | .\" manual provided the copyright notice and this permission notice are |
fea681da MK |
6 | .\" preserved on all copies. |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
24 | .\" |
25 | .\" Added correction due to Nick Duffek <nsd@bbc.com>, aeb, 960426 | |
26 | .\" Modified Wed Nov 6 04:00:31 1996 by Eric S. Raymond <esr@thyrsus.com> | |
c11b1abf | 27 | .\" Modified, 8 Jan 2003, Michael Kerrisk, <mtk.manpages@gmail.com> |
fea681da | 28 | .\" Removed EIDRM from errors - that can't happen... |
c11b1abf | 29 | .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 30 | .\" Added notes on capability requirements |
c11b1abf | 31 | .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com> |
c952e226 MK |
32 | .\" Language and formatting clean-ups |
33 | .\" Added notes on /proc files | |
fea681da | 34 | .\" |
460495ca | 35 | .TH MSGGET 2 2015-08-08 "Linux" "Linux Programmer's Manual" |
fea681da | 36 | .SH NAME |
47f065d6 | 37 | msgget \- get a System V message queue identifier |
fea681da MK |
38 | .SH SYNOPSIS |
39 | .nf | |
2fadbfb5 MK |
40 | .B #include <sys/types.h> |
41 | .B #include <sys/ipc.h> | |
42 | .B #include <sys/msg.h> | |
ab04533a | 43 | |
34e8ac03 | 44 | .BI "int msgget(key_t " key ", int " msgflg ); |
ab04533a | 45 | .fi |
fea681da | 46 | .SH DESCRIPTION |
c952e226 MK |
47 | The |
48 | .BR msgget () | |
efbfd7ec | 49 | system call returns the System\ V message queue identifier associated |
fea681da MK |
50 | with the value of the |
51 | .I key | |
52 | argument. | |
53 | A new message queue is created if | |
54 | .I key | |
55 | has the value | |
56 | .B IPC_PRIVATE | |
57 | or | |
58 | .I key | |
59 | isn't | |
60 | .BR IPC_PRIVATE , | |
61 | no message queue with the given key | |
0daa9e92 | 62 | .I key |
fea681da MK |
63 | exists, and |
64 | .B IPC_CREAT | |
c952e226 MK |
65 | is specified in |
66 | .IR msgflg . | |
67 | .PP | |
68 | If | |
fea681da | 69 | .I msgflg |
c952e226 | 70 | specifies both |
fea681da MK |
71 | .B IPC_CREAT |
72 | and | |
73 | .B IPC_EXCL | |
74 | and a message queue already exists for | |
c952e226 MK |
75 | .IR key , |
76 | then | |
77 | .BR msgget () | |
c13182ef | 78 | fails with |
c952e226 MK |
79 | .I errno |
80 | set to | |
81 | .BR EEXIST . | |
c13182ef | 82 | (This is analogous to the effect of the combination |
c952e226 MK |
83 | .B O_CREAT | O_EXCL |
84 | for | |
85 | .BR open (2).) | |
fea681da | 86 | .PP |
c952e226 | 87 | Upon creation, the least significant bits of the argument |
fea681da | 88 | .I msgflg |
c952e226 | 89 | define the permissions of the message queue. |
fea681da | 90 | These permission bits have the same format and semantics |
c13182ef | 91 | as the permissions specified for the |
c952e226 MK |
92 | .I mode |
93 | argument of | |
94 | .BR open (2). | |
95 | (The execute permissions are not used.) | |
fea681da MK |
96 | .PP |
97 | If a new message queue is created, | |
c952e226 | 98 | then its associated data structure |
1176900f | 99 | .I msqid_ds |
c952e226 MK |
100 | (see |
101 | .BR msgctl (2)) | |
d9bfdb9c | 102 | is initialized as follows: |
fea681da | 103 | .IP |
c952e226 | 104 | .I msg_perm.cuid |
fea681da | 105 | and |
c952e226 | 106 | .I msg_perm.uid |
499d62f2 | 107 | are set to the effective user ID of the calling process. |
fea681da | 108 | .IP |
c952e226 | 109 | .I msg_perm.cgid |
fea681da | 110 | and |
c952e226 | 111 | .I msg_perm.gid |
499d62f2 | 112 | are set to the effective group ID of the calling process. |
fea681da | 113 | .IP |
c952e226 MK |
114 | The least significant 9 bits of |
115 | .I msg_perm.mode | |
116 | are set to the least significant 9 bits of | |
fea681da MK |
117 | .IR msgflg . |
118 | .IP | |
c952e226 MK |
119 | .IR msg_qnum , |
120 | .IR msg_lspid , | |
121 | .IR msg_lrpid , | |
a797afac | 122 | .IR msg_stime , |
fea681da | 123 | and |
c952e226 | 124 | .I msg_rtime |
fea681da MK |
125 | are set to 0. |
126 | .IP | |
c952e226 | 127 | .I msg_ctime |
fea681da MK |
128 | is set to the current time. |
129 | .IP | |
c952e226 | 130 | .I msg_qbytes |
fea681da MK |
131 | is set to the system limit |
132 | .BR MSGMNB . | |
133 | .PP | |
c952e226 | 134 | If the message queue already exists the permissions are |
fea681da MK |
135 | verified, and a check is made to see if it is marked for |
136 | destruction. | |
47297adb | 137 | .SH RETURN VALUE |
fea681da | 138 | If successful, the return value will be the message queue identifier (a |
2fda57bd | 139 | nonnegative integer), otherwise \-1 |
fea681da | 140 | with |
c952e226 | 141 | .I errno |
fea681da MK |
142 | indicating the error. |
143 | .SH ERRORS | |
144 | On failure, | |
c952e226 | 145 | .I errno |
fea681da | 146 | is set to one of the following values: |
89b3c6b8 | 147 | .TP |
fea681da MK |
148 | .B EACCES |
149 | A message queue exists for | |
150 | .IR key , | |
151 | but the calling process does not have permission to access the queue, | |
152 | and does not have the | |
0daa9e92 | 153 | .B CAP_IPC_OWNER |
fea681da MK |
154 | capability. |
155 | .TP | |
156 | .B EEXIST | |
fea681da MK |
157 | .B IPC_CREAT |
158 | and | |
85889360 MK |
159 | .BR IPC_EXCL |
160 | were specified in | |
161 | .IR msgflg , | |
162 | but a message queue already exists for | |
163 | .IR key . | |
fea681da MK |
164 | .TP |
165 | .B ENOENT | |
166 | No message queue exists for | |
167 | .I key | |
168 | and | |
169 | .I msgflg | |
c952e226 | 170 | did not specify |
fea681da MK |
171 | .BR IPC_CREAT . |
172 | .TP | |
173 | .B ENOMEM | |
c952e226 MK |
174 | A message queue has to be created but the system does not have enough |
175 | memory for the new data structure. | |
fea681da MK |
176 | .TP |
177 | .B ENOSPC | |
178 | A message queue has to be created but the system limit for the maximum | |
179 | number of message queues | |
180 | .RB ( MSGMNI ) | |
181 | would be exceeded. | |
47297adb | 182 | .SH CONFORMING TO |
c33c7b9a | 183 | POSIX.1-2001, POSIX.1-2008, SVr4. |
fea681da | 184 | .SH NOTES |
f6652463 MK |
185 | The inclusion of |
186 | .I <sys/types.h> | |
187 | and | |
188 | .I <sys/ipc.h> | |
189 | isn't required on Linux or by any version of POSIX. | |
190 | However, | |
191 | some old implementations required the inclusion of these header files, | |
192 | and the SVID also documented their inclusion. | |
193 | Applications intended to be portable to such old systems may need | |
194 | to include these header files. | |
195 | .\" Like Linux, the FreeBSD man pages still document | |
196 | .\" the inclusion of these header files. | |
197 | ||
fea681da MK |
198 | .B IPC_PRIVATE |
199 | isn't a flag field but a | |
c952e226 | 200 | .I key_t |
fea681da MK |
201 | type. |
202 | If this special value is used for | |
203 | .IR key , | |
c952e226 | 204 | the system call ignores everything but the least significant 9 bits of |
fea681da MK |
205 | .I msgflg |
206 | and creates a new message queue (on success). | |
207 | .PP | |
208 | The following is a system limit on message queue resources affecting a | |
c952e226 | 209 | .BR msgget () |
fea681da | 210 | call: |
89b3c6b8 | 211 | .TP |
fea681da | 212 | .B MSGMNI |
a75f73c2 MK |
213 | System-wide limit on the number of message queues. |
214 | Before Linux 3.19, | |
215 | .\" commit 0050ee059f7fc86b1df2527aaa14ed5dc72f9973 | |
216 | the default value for this limit was calculated using a formula | |
217 | based on available system memory. | |
218 | Since Linux 3.19, the default value is 32,000. | |
219 | On Linux, this limit can be read and modified via | |
220 | .IR /proc/sys/kernel/msgmni . | |
c634028a | 221 | .SS Linux notes |
3d565ddf | 222 | Until version 2.3.20, Linux would return |
0daa9e92 | 223 | .B EIDRM |
682edefb | 224 | for a |
4fb31341 MK |
225 | .BR msgget () |
226 | on a message queue scheduled for deletion. | |
fea681da | 227 | .SH BUGS |
682edefb | 228 | The name choice |
0daa9e92 | 229 | .B IPC_PRIVATE |
9091595d MK |
230 | was perhaps unfortunate, |
231 | .B IPC_NEW | |
fea681da | 232 | would more clearly show its function. |
47297adb | 233 | .SH SEE ALSO |
fea681da MK |
234 | .BR msgctl (2), |
235 | .BR msgrcv (2), | |
236 | .BR msgsnd (2), | |
237 | .BR ftok (3), | |
a9b305d6 | 238 | .BR capabilities (7), |
2c5e151c MK |
239 | .BR mq_overview (7), |
240 | .BR svipc (7) |