xref: /netbsd/lib/libc/sys/msgget.2 (revision bf9ec67e)
1.\"	$NetBSD: msgget.2,v 1.10 2002/02/08 01:28:19 ross 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 August 25, 1999
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.Fd #include \*[Lt]sys/msg.h\*[Gt]
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 .
61.Pp
62If a new message queue is created, the data structure associated with it (the
63.Va msqid_ds
64structure, see
65.Xr msgctl 2 )
66is initialized as follows:
67.Bl -bullet
68.It
69.Va msg_perm.cuid
70and
71.Va msg_perm.uid
72are set to the effective uid of the calling process.
73.It
74.Va msg_perm.gid
75and
76.Va msg_perm.cgid
77are set to the effective gid of the calling process.
78.It
79.Va msg_perm.mode
80is set to the lower 9 bits of
81.Fa msgflg .
82.It
83.Va msg_qnum ,
84.Va msg_lspid ,
85.Va msg_lrpid ,
86.Va msg_rtime ,
87and
88.Va msg_stime
89are set to 0.
90.It
91.Va msg_qbytes
92is set to the system wide maximum value for the number of bytes in a queue
93.Pq Dv MSGMNB .
94.It
95.Va msg_ctime
96is set to the current time.
97.El
98.Sh RETURN VALUES
99Upon successful completion a positive message queue identifier is returned.
100Otherwise, -1 is returned and the global variable
101.Va errno
102is set to indicate the error.
103.Sh ERRORS
104.Bl -tag -width Er
105.It Bq Er EACCES
106A message queue is already associated with
107.Fa key
108and the caller has no permission to access it.
109.It Bq Er EEXIST
110Both
111.Dv IPC_CREAT
112and
113.Dv IPC_EXCL
114are set in
115.Fa msgflg ,
116and a message queue is already associated with
117.Fa key .
118.It Bq Er ENOSPC
119A new message queue could not be created because the system limit for
120the number of message queues has been reached.
121.It Bq Er ENOENT
122.Dv IPC_CREAT
123is not set in
124.Fa msgflg
125and no message queue associated with
126.Fa key
127was found.
128.El
129.Sh SEE ALSO
130.Xr msgctl 2 ,
131.Xr msgrcv 2 ,
132.Xr msgsnd 2 ,
133.Xr ftok 3
134.Sh STANDARDS
135The
136.Nm
137system call conforms to
138.St -xsh5 .
139.Sh HISTORY
140Message queues appeared in the first release of
141.At V .
142