.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved 
.TH "MSGGET" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" msgget 
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.SH NAME
msgget \- get the XSI message queue identifier
.SH SYNOPSIS
.LP
\fB#include <sys/msg.h>
.br
.sp
int msgget(key_t\fP \fIkey\fP\fB, int\fP \fImsgflg\fP\fB); \fP
\fB
.br
\fP
.SH DESCRIPTION
.LP
The \fImsgget\fP() function operates on XSI message queues (see the
Base Definitions volume of IEEE\ Std\ 1003.1-2001,
Section 3.224, Message Queue). It is unspecified whether this function
interoperates with the realtime interprocess communication facilities
defined in \fIRealtime\fP .
.LP
The \fImsgget\fP() function shall return the message queue identifier
associated with the argument \fIkey\fP.
.LP
A message queue identifier, associated message queue, and data structure
(see \fI<sys/msg.h>\fP), shall be created for the argument \fIkey\fP
if one of the following is
true:
.IP " *" 3
The argument \fIkey\fP is equal to IPC_PRIVATE.
.LP
.IP " *" 3
The argument \fIkey\fP does not already have a message queue identifier
associated with it, and (\fImsgflg\fP & IPC_CREAT)
is non-zero.
.LP
.LP
Upon creation, the data structure associated with the new message
queue identifier shall be initialized as follows:
.IP " *" 3
\fBmsg_perm.cuid\fP, \fBmsg_perm.uid\fP, \fBmsg_perm.cgid\fP, and
\fBmsg_perm.gid\fP shall be set equal to the effective
user ID and effective group ID, respectively, of the calling process.
.LP
.IP " *" 3
The low-order 9 bits of \fBmsg_perm.mode\fP shall be set equal to
the low-order 9 bits of \fImsgflg\fP.
.LP
.IP " *" 3
\fBmsg_qnum\fP, \fBmsg_lspid\fP, \fBmsg_lrpid\fP, \fBmsg_stime\fP,
and \fBmsg_rtime\fP shall be set equal to 0.
.LP
.IP " *" 3
\fBmsg_ctime\fP shall be set equal to the current time.
.LP
.IP " *" 3
\fBmsg_qbytes\fP shall be set equal to the system limit.
.LP
.SH RETURN VALUE
.LP
Upon successful completion, \fImsgget\fP() shall return a non-negative
integer, namely a message queue identifier. Otherwise,
it shall return -1 and set \fIerrno\fP to indicate the error.
.SH ERRORS
.LP
The \fImsgget\fP() function shall fail if:
.TP 7
.B EACCES
A message queue identifier exists for the argument \fIkey\fP, but
operation permission as specified by the low-order 9 bits of
\fImsgflg\fP would not be granted; see \fIXSI Interprocess Communication\fP
\&.
.TP 7
.B EEXIST
A message queue identifier exists for the argument \fIkey\fP but ((\fImsgflg\fP
& IPC_CREAT) && (\fImsgflg\fP
& IPC_EXCL)) is non-zero.
.TP 7
.B ENOENT
A message queue identifier does not exist for the argument \fIkey\fP
and (\fImsgflg\fP & IPC_CREAT) is 0.
.TP 7
.B ENOSPC
A message queue identifier is to be created but the system-imposed
limit on the maximum number of allowed message queue
identifiers system-wide would be exceeded.
.sp
.LP
\fIThe following sections are informative.\fP
.SH EXAMPLES
.LP
None.
.SH APPLICATION USAGE
.LP
The POSIX Realtime Extension defines alternative interfaces for interprocess
communication (IPC). Application developers who
need to use IPC should design their applications so that modules using
the IPC routines described in \fIXSI Interprocess Communication\fP
can be easily modified to use the alternative
interfaces.
.SH RATIONALE
.LP
None.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIXSI Interprocess Communication\fP, \fIRealtime\fP, \fImq_close\fP(),
\fImq_getattr\fP(), \fImq_notify\fP(), \fImq_open\fP(), \fImq_receive\fP(),
\fImq_send\fP(), \fImq_setattr\fP(), \fImq_unlink\fP(), \fImsgctl\fP(),
\fImsgrcv\fP(),
\fImsgsnd\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
\fI<sys/msg.h>\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
