]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/msgget.2
s/nonnegative/non-negative/
[thirdparty/man-pages.git] / man2 / msgget.2
CommitLineData
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
35msgget \- 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
49The
50.BR msgget ()
51system call returns the message queue identifier associated
fea681da
MK
52with the value of the
53.I key
54argument.
55A new message queue is created if
56.I key
57has the value
58.B IPC_PRIVATE
59or
60.I key
61isn't
62.BR IPC_PRIVATE ,
63no message queue with the given key
64.IR key
65exists, and
66.B IPC_CREAT
c952e226
MK
67is specified in
68.IR msgflg .
69.PP
70If
fea681da 71.I msgflg
c952e226 72specifies both
fea681da
MK
73.B IPC_CREAT
74and
75.B IPC_EXCL
76and a message queue already exists for
c952e226
MK
77.IR key ,
78then
79.BR msgget ()
c13182ef 80fails with
c952e226
MK
81.I errno
82set to
83.BR EEXIST .
c13182ef 84(This is analogous to the effect of the combination
c952e226
MK
85.B O_CREAT | O_EXCL
86for
87.BR open (2).)
fea681da 88.PP
c952e226 89Upon creation, the least significant bits of the argument
fea681da 90.I msgflg
c952e226 91define the permissions of the message queue.
fea681da 92These permission bits have the same format and semantics
c13182ef 93as the permissions specified for the
c952e226
MK
94.I mode
95argument of
96.BR open (2).
97(The execute permissions are not used.)
fea681da
MK
98.PP
99If a new message queue is created,
c952e226 100then its associated data structure
1176900f 101.I msqid_ds
c952e226
MK
102(see
103.BR msgctl (2))
104is initialised as follows:
fea681da 105.IP
c952e226 106.I msg_perm.cuid
fea681da 107and
c952e226 108.I msg_perm.uid
499d62f2 109are set to the effective user ID of the calling process.
fea681da 110.IP
c952e226 111.I msg_perm.cgid
fea681da 112and
c952e226 113.I msg_perm.gid
499d62f2 114are set to the effective group ID of the calling process.
fea681da 115.IP
c952e226
MK
116The least significant 9 bits of
117.I msg_perm.mode
118are 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 125and
c952e226 126.I msg_rtime
fea681da
MK
127are set to 0.
128.IP
c952e226 129.I msg_ctime
fea681da
MK
130is set to the current time.
131.IP
c952e226 132.I msg_qbytes
fea681da
MK
133is set to the system limit
134.BR MSGMNB .
135.PP
c952e226 136If the message queue already exists the permissions are
fea681da
MK
137verified, and a check is made to see if it is marked for
138destruction.
139.SH "RETURN VALUE"
140If successful, the return value will be the message queue identifier (a
18be658d 141non-negative integer), otherwise \-1
fea681da 142with
c952e226 143.I errno
fea681da
MK
144indicating the error.
145.SH ERRORS
146On failure,
c952e226 147.I errno
fea681da
MK
148is set to one of the following values:
149.TP 11
150.B EACCES
151A message queue exists for
152.IR key ,
153but the calling process does not have permission to access the queue,
154and does not have the
155.BR CAP_IPC_OWNER
156capability.
157.TP
158.B EEXIST
159A message queue exists for
8478ee02 160.I key
fea681da
MK
161and
162.I msgflg
c952e226 163specified both
fea681da
MK
164.B IPC_CREAT
165and
166.BR IPC_EXCL .
167.TP
168.B ENOENT
169No message queue exists for
170.I key
171and
172.I msgflg
c952e226 173did not specify
fea681da
MK
174.BR IPC_CREAT .
175.TP
176.B ENOMEM
c952e226
MK
177A message queue has to be created but the system does not have enough
178memory for the new data structure.
fea681da
MK
179.TP
180.B ENOSPC
181A message queue has to be created but the system limit for the maximum
182number of message queues
183.RB ( MSGMNI )
184would be exceeded.
185.SH NOTES
186.B IPC_PRIVATE
187isn't a flag field but a
c952e226 188.I key_t
fea681da
MK
189type.
190If this special value is used for
191.IR key ,
c952e226 192the system call ignores everything but the least significant 9 bits of
fea681da
MK
193.I msgflg
194and creates a new message queue (on success).
195.PP
196The following is a system limit on message queue resources affecting a
c952e226 197.BR msgget ()
fea681da
MK
198call:
199.TP 11
200.B MSGMNI
201System wide maximum number of message queues: policy
c952e226
MK
202dependent
203(on Linux, this limit can be read and modified via
204.IR /proc/sys/kernel/msgmni ).
fea681da
MK
205.SH BUGS
206The name choice IPC_PRIVATE was perhaps unfortunate, IPC_NEW
207would more clearly show its function.
208.SH "CONFORMING TO"
97c1eac8
MK
209SVr4, POSIX.1-2001.
210.SH "LINUX NOTES"
fea681da 211Until version 2.3.20 Linux would return EIDRM for a
c952e226 212.BR msgget ()
fea681da
MK
213on 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)