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