1.\" $OpenBSD: msgget.2,v 1.14 2019/07/18 13:32:40 schwarze Exp $ 2.\" $NetBSD: msgget.2,v 1.1 1995/10/16 23:49:19 jtc Exp $ 3.\" 4.\" Copyright (c) 1995 Frank van der Linden 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed for the NetBSD Project 18.\" by Frank van der Linden 19.\" 4. The name of the author may not be used to endorse or promote products 20.\" derived from this software without specific prior written permission 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32.\"/ 33.Dd $Mdocdate: July 18 2019 $ 34.Dt MSGGET 2 35.Os 36.Sh NAME 37.Nm msgget 38.Nd get message queue 39.Sh SYNOPSIS 40.In sys/msg.h 41.Ft int 42.Fn msgget "key_t key" "int msgflg" 43.Sh DESCRIPTION 44.Fn msgget 45returns the message queue identifier associated with 46.Fa key . 47A message queue identifier is a unique integer greater than zero. 48.Pp 49A message queue is created if either 50.Fa key 51is equal to 52.Dv IPC_PRIVATE , 53or 54.Fa key 55does not have a message queue identifier associated with it, and the 56.Dv IPC_CREAT 57bit is set in 58.Fa msgflg . 59.Pp 60If a new message queue is created, the data structure associated with it (the 61.Vt msqid_ds 62structure, see 63.Xr msgctl 2 ) 64is initialized as follows: 65.Bl -bullet 66.It 67.Fa msg_perm.cuid 68and 69.Fa msg_perm.uid 70are set to the effective UID of the calling process. 71.It 72.Fa msg_perm.gid 73and 74.Fa msg_perm.cgid 75are set to the effective GID of the calling process. 76.It 77.Fa msg_perm.mode 78is set to the lower 9 bits of 79.Fa msgflg . 80.It 81.Fa msg_cbytes , 82.Fa msg_qnum , 83.Fa msg_lspid , 84.Fa msg_lrpid , 85.Fa msg_rtime , 86and 87.Fa msg_stime 88are set to 0. 89.It 90.Fa msg_qbytes 91is set to the system wide maximum value for the number of bytes in a queue 92.Pq Dv MSGMNB . 93.It 94.Fa msg_ctime 95is set to the current time. 96.El 97.Sh RETURN VALUES 98Upon successful completion a positive message queue identifier is returned. 99Otherwise, \-1 is returned and the global variable 100.Va errno 101is set to indicate the error. 102.Sh ERRORS 103.Bl -tag -width Er 104.It Bq Er EACCES 105A message queue is already associated with 106.Fa key 107and the caller has no permission to access it. 108.It Bq Er EEXIST 109Both 110.Dv IPC_CREAT 111and 112.Dv IPC_EXCL 113are set in 114.Fa msgflg , 115and a message queue is already associated with 116.Fa key . 117.It Bq Er ENOSPC 118A new message queue could not be created because the system limit for 119the number of message queues has been reached. 120.It Bq Er ENOENT 121.Dv IPC_CREAT 122was not set in 123.Fa msgflg 124and no message queue associated with 125.Fa key 126was found. 127.El 128.Sh SEE ALSO 129.Xr msgctl 2 , 130.Xr msgrcv 2 , 131.Xr msgsnd 2 , 132.Xr ftok 3 133.Sh STANDARDS 134The 135.Fn msgget 136function conforms to the X/Open System Interfaces option of 137.St -p1003.1-2008 . 138.Sh HISTORY 139Message queues first appeared in 140.At V.1 141and have been available since 142.Nx 1.0 . 143