]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/msgget.2
dlerror.3: wfix
[thirdparty/man-pages.git] / man2 / msgget.2
CommitLineData
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.\"
6d322d5f 35.TH MSGGET 2 2015-02-21 "Linux" "Linux Programmer's Manual"
fea681da 36.SH NAME
47f065d6 37msgget \- 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
47The
48.BR msgget ()
efbfd7ec 49system call returns the System\ V message queue identifier associated
fea681da
MK
50with the value of the
51.I key
52argument.
53A new message queue is created if
54.I key
55has the value
56.B IPC_PRIVATE
57or
58.I key
59isn't
60.BR IPC_PRIVATE ,
61no message queue with the given key
0daa9e92 62.I key
fea681da
MK
63exists, and
64.B IPC_CREAT
c952e226
MK
65is specified in
66.IR msgflg .
67.PP
68If
fea681da 69.I msgflg
c952e226 70specifies both
fea681da
MK
71.B IPC_CREAT
72and
73.B IPC_EXCL
74and a message queue already exists for
c952e226
MK
75.IR key ,
76then
77.BR msgget ()
c13182ef 78fails with
c952e226
MK
79.I errno
80set to
81.BR EEXIST .
c13182ef 82(This is analogous to the effect of the combination
c952e226
MK
83.B O_CREAT | O_EXCL
84for
85.BR open (2).)
fea681da 86.PP
c952e226 87Upon creation, the least significant bits of the argument
fea681da 88.I msgflg
c952e226 89define the permissions of the message queue.
fea681da 90These permission bits have the same format and semantics
c13182ef 91as the permissions specified for the
c952e226
MK
92.I mode
93argument of
94.BR open (2).
95(The execute permissions are not used.)
fea681da
MK
96.PP
97If a new message queue is created,
c952e226 98then its associated data structure
1176900f 99.I msqid_ds
c952e226
MK
100(see
101.BR msgctl (2))
d9bfdb9c 102is initialized as follows:
fea681da 103.IP
c952e226 104.I msg_perm.cuid
fea681da 105and
c952e226 106.I msg_perm.uid
499d62f2 107are set to the effective user ID of the calling process.
fea681da 108.IP
c952e226 109.I msg_perm.cgid
fea681da 110and
c952e226 111.I msg_perm.gid
499d62f2 112are set to the effective group ID of the calling process.
fea681da 113.IP
c952e226
MK
114The least significant 9 bits of
115.I msg_perm.mode
116are 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 123and
c952e226 124.I msg_rtime
fea681da
MK
125are set to 0.
126.IP
c952e226 127.I msg_ctime
fea681da
MK
128is set to the current time.
129.IP
c952e226 130.I msg_qbytes
fea681da
MK
131is set to the system limit
132.BR MSGMNB .
133.PP
c952e226 134If the message queue already exists the permissions are
fea681da
MK
135verified, and a check is made to see if it is marked for
136destruction.
47297adb 137.SH RETURN VALUE
fea681da 138If successful, the return value will be the message queue identifier (a
2fda57bd 139nonnegative integer), otherwise \-1
fea681da 140with
c952e226 141.I errno
fea681da
MK
142indicating the error.
143.SH ERRORS
144On failure,
c952e226 145.I errno
fea681da 146is set to one of the following values:
89b3c6b8 147.TP
fea681da
MK
148.B EACCES
149A message queue exists for
150.IR key ,
151but the calling process does not have permission to access the queue,
152and does not have the
0daa9e92 153.B CAP_IPC_OWNER
fea681da
MK
154capability.
155.TP
156.B EEXIST
fea681da
MK
157.B IPC_CREAT
158and
85889360
MK
159.BR IPC_EXCL
160were specified in
161.IR msgflg ,
162but a message queue already exists for
163.IR key .
fea681da
MK
164.TP
165.B ENOENT
166No message queue exists for
167.I key
168and
169.I msgflg
c952e226 170did not specify
fea681da
MK
171.BR IPC_CREAT .
172.TP
173.B ENOMEM
c952e226
MK
174A message queue has to be created but the system does not have enough
175memory for the new data structure.
fea681da
MK
176.TP
177.B ENOSPC
178A message queue has to be created but the system limit for the maximum
179number of message queues
180.RB ( MSGMNI )
181would be exceeded.
47297adb 182.SH CONFORMING TO
c33c7b9a 183POSIX.1-2001, POSIX.1-2008, SVr4.
fea681da 184.SH NOTES
f6652463
MK
185The inclusion of
186.I <sys/types.h>
187and
188.I <sys/ipc.h>
189isn't required on Linux or by any version of POSIX.
190However,
191some old implementations required the inclusion of these header files,
192and the SVID also documented their inclusion.
193Applications intended to be portable to such old systems may need
194to 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
199isn't a flag field but a
c952e226 200.I key_t
fea681da
MK
201type.
202If this special value is used for
203.IR key ,
c952e226 204the system call ignores everything but the least significant 9 bits of
fea681da
MK
205.I msgflg
206and creates a new message queue (on success).
207.PP
208The following is a system limit on message queue resources affecting a
c952e226 209.BR msgget ()
fea681da 210call:
89b3c6b8 211.TP
fea681da 212.B MSGMNI
a75f73c2
MK
213System-wide limit on the number of message queues.
214Before Linux 3.19,
215.\" commit 0050ee059f7fc86b1df2527aaa14ed5dc72f9973
216the default value for this limit was calculated using a formula
217based on available system memory.
218Since Linux 3.19, the default value is 32,000.
219On Linux, this limit can be read and modified via
220.IR /proc/sys/kernel/msgmni .
c634028a 221.SS Linux notes
3d565ddf 222Until version 2.3.20, Linux would return
0daa9e92 223.B EIDRM
682edefb 224for a
4fb31341
MK
225.BR msgget ()
226on a message queue scheduled for deletion.
fea681da 227.SH BUGS
682edefb 228The name choice
0daa9e92 229.B IPC_PRIVATE
9091595d
MK
230was perhaps unfortunate,
231.B IPC_NEW
fea681da 232would 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)