]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/msgget.2
man*/: srcfix (Use .P instead of .PP or .LP)
[thirdparty/man-pages.git] / man2 / msgget.2
CommitLineData
fea681da
MK
1.\" Copyright 1993 Giorgio Ciucci <giorgio@crcc.it>
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
4.\"
5.\" Added correction due to Nick Duffek <nsd@bbc.com>, aeb, 960426
6.\" Modified Wed Nov 6 04:00:31 1996 by Eric S. Raymond <esr@thyrsus.com>
c11b1abf 7.\" Modified, 8 Jan 2003, Michael Kerrisk, <mtk.manpages@gmail.com>
fea681da 8.\" Removed EIDRM from errors - that can't happen...
c11b1abf 9.\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 10.\" Added notes on capability requirements
c11b1abf 11.\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
c952e226
MK
12.\" Language and formatting clean-ups
13.\" Added notes on /proc files
fea681da 14.\"
4c1c5274 15.TH msgget 2 (date) "Linux man-pages (unreleased)"
fea681da 16.SH NAME
47f065d6 17msgget \- get a System V message queue identifier
2c6b463e
AC
18.SH LIBRARY
19Standard C library
8fc3b2cf 20.RI ( libc ", " \-lc )
fea681da
MK
21.SH SYNOPSIS
22.nf
2fadbfb5 23.B #include <sys/msg.h>
c6d039a3 24.P
34e8ac03 25.BI "int msgget(key_t " key ", int " msgflg );
ab04533a 26.fi
fea681da 27.SH DESCRIPTION
c952e226
MK
28The
29.BR msgget ()
efbfd7ec 30system call returns the System\ V message queue identifier associated
fea681da
MK
31with the value of the
32.I key
33argument.
f8ac3de3
MK
34It may be used either to obtain the identifier of a previously created
35message queue (when
36.I msgflg
37is zero and
38.I key
39does not have the value
40.BR IPC_PRIVATE ),
41or to create a new set.
c6d039a3 42.P
fea681da
MK
43A new message queue is created if
44.I key
45has the value
46.B IPC_PRIVATE
47or
48.I key
49isn't
50.BR IPC_PRIVATE ,
51no message queue with the given key
0daa9e92 52.I key
fea681da
MK
53exists, and
54.B IPC_CREAT
c952e226
MK
55is specified in
56.IR msgflg .
c6d039a3 57.P
c952e226 58If
fea681da 59.I msgflg
c952e226 60specifies both
fea681da
MK
61.B IPC_CREAT
62and
63.B IPC_EXCL
64and a message queue already exists for
c952e226
MK
65.IR key ,
66then
67.BR msgget ()
c13182ef 68fails with
c952e226
MK
69.I errno
70set to
71.BR EEXIST .
c13182ef 72(This is analogous to the effect of the combination
c952e226
MK
73.B O_CREAT | O_EXCL
74for
75.BR open (2).)
c6d039a3 76.P
c952e226 77Upon creation, the least significant bits of the argument
fea681da 78.I msgflg
c952e226 79define the permissions of the message queue.
fea681da 80These permission bits have the same format and semantics
c13182ef 81as the permissions specified for the
c952e226
MK
82.I mode
83argument of
84.BR open (2).
85(The execute permissions are not used.)
c6d039a3 86.P
fea681da 87If a new message queue is created,
c952e226 88then its associated data structure
1176900f 89.I msqid_ds
c952e226
MK
90(see
91.BR msgctl (2))
d9bfdb9c 92is initialized as follows:
cdede5cd 93.IP \[bu] 3
c952e226 94.I msg_perm.cuid
fea681da 95and
c952e226 96.I msg_perm.uid
499d62f2 97are set to the effective user ID of the calling process.
cdede5cd 98.IP \[bu]
c952e226 99.I msg_perm.cgid
fea681da 100and
c952e226 101.I msg_perm.gid
499d62f2 102are set to the effective group ID of the calling process.
cdede5cd 103.IP \[bu]
c952e226
MK
104The least significant 9 bits of
105.I msg_perm.mode
106are set to the least significant 9 bits of
fea681da 107.IR msgflg .
cdede5cd 108.IP \[bu]
c952e226
MK
109.IR msg_qnum ,
110.IR msg_lspid ,
111.IR msg_lrpid ,
a797afac 112.IR msg_stime ,
fea681da 113and
c952e226 114.I msg_rtime
fea681da 115are set to 0.
cdede5cd 116.IP \[bu]
c952e226 117.I msg_ctime
fea681da 118is set to the current time.
cdede5cd 119.IP \[bu]
c952e226 120.I msg_qbytes
fea681da
MK
121is set to the system limit
122.BR MSGMNB .
c6d039a3 123.P
c952e226 124If the message queue already exists the permissions are
fea681da
MK
125verified, and a check is made to see if it is marked for
126destruction.
47297adb 127.SH RETURN VALUE
9862ec0c
MK
128On success,
129.BR msgget ()
130returns the message queue identifier (a nonnegative integer).
131On failure, \-1 is returned, and
c952e226 132.I errno
9862ec0c 133is set to indicate the error.
fea681da 134.SH ERRORS
89b3c6b8 135.TP
fea681da
MK
136.B EACCES
137A message queue exists for
138.IR key ,
139but the calling process does not have permission to access the queue,
140and does not have the
0daa9e92 141.B CAP_IPC_OWNER
3294109d 142capability in the user namespace that governs its IPC namespace.
fea681da
MK
143.TP
144.B EEXIST
fea681da
MK
145.B IPC_CREAT
146and
1ae6b2c7 147.B IPC_EXCL
85889360
MK
148were specified in
149.IR msgflg ,
150but a message queue already exists for
151.IR key .
fea681da
MK
152.TP
153.B ENOENT
154No message queue exists for
155.I key
156and
157.I msgflg
c952e226 158did not specify
fea681da
MK
159.BR IPC_CREAT .
160.TP
161.B ENOMEM
c952e226
MK
162A message queue has to be created but the system does not have enough
163memory for the new data structure.
fea681da
MK
164.TP
165.B ENOSPC
166A message queue has to be created but the system limit for the maximum
167number of message queues
168.RB ( MSGMNI )
169would be exceeded.
3113c7f3 170.SH STANDARDS
4131356c
AC
171POSIX.1-2008.
172.SH HISTORY
173POSIX.1-2001, SVr4.
174.SS Linux
175Until Linux 2.3.20, Linux would return
176.B EIDRM
177for a
178.BR msgget ()
179on a message queue scheduled for deletion.
fea681da
MK
180.SH NOTES
181.B IPC_PRIVATE
182isn't a flag field but a
c952e226 183.I key_t
fea681da
MK
184type.
185If this special value is used for
186.IR key ,
c952e226 187the system call ignores everything but the least significant 9 bits of
fea681da
MK
188.I msgflg
189and creates a new message queue (on success).
c6d039a3 190.P
fea681da 191The following is a system limit on message queue resources affecting a
c952e226 192.BR msgget ()
fea681da 193call:
89b3c6b8 194.TP
fea681da 195.B MSGMNI
a75f73c2
MK
196System-wide limit on the number of message queues.
197Before Linux 3.19,
198.\" commit 0050ee059f7fc86b1df2527aaa14ed5dc72f9973
199the default value for this limit was calculated using a formula
200based on available system memory.
201Since Linux 3.19, the default value is 32,000.
202On Linux, this limit can be read and modified via
203.IR /proc/sys/kernel/msgmni .
fea681da 204.SH BUGS
682edefb 205The name choice
0daa9e92 206.B IPC_PRIVATE
9091595d
MK
207was perhaps unfortunate,
208.B IPC_NEW
fea681da 209would more clearly show its function.
47297adb 210.SH SEE ALSO
fea681da
MK
211.BR msgctl (2),
212.BR msgrcv (2),
213.BR msgsnd (2),
214.BR ftok (3),
a9b305d6 215.BR capabilities (7),
2c5e151c 216.BR mq_overview (7),
343cdc5a 217.BR sysvipc (7)