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