'\"macro stdmacro
.if n .pH g2.msgget @(#)msgget	40.12 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} msgget 2 "" "\&"
.if \nX=1 .ds x} msgget 2 ""
.if \nX=2 .ds x} msgget 2 "" "\&"
.if \nX=3 .ds x} msgget "" "" "\&"
.TH \*(x}
.SH NAME
\f4msgget\f1 \- get message queue
.SH SYNOPSIS
\f4#include <sys/types.h>\f1
.br
\f4#include <sys/ipc.h>\f1
.br
\f4#include <sys/msg.h>\f1
.PP
.nf
\f4int msgget(key_t key, int msgflg);\f1
.fi
.SH DESCRIPTION
\f4msgget\fP
returns the message queue identifier associated with
.IR key .
.PP
A message queue identifier and associated message queue and data structure
[see
\f4intro\fP(2)]
are created for
.I key
if one of the following are true:
.IP 
.I key
is
\f4IPC_PRIVATE\f1.
.IP
.I key
does not already have a message queue identifier associated with it, and
(\f2msgflg\f4&IPC_CREAT\f1)
is true.
.PP
On creation, the data structure associated with the new message queue
identifier is initialized as follows:
.IP
\f4msg_perm.cuid\f1, \f4msg_perm.uid\f1,
\f4msg_perm.cgid\f1, and \f4msg_perm.gid\f1
are set to the effective user
.SM ID
and effective group
.SM ID\*S,
respectively, of the calling process.
.IP
The low-order 9 bits of
\f4msg_perm.mode\f1
are set to the low-order 9 bits of
.IR msgflg .
.IP
\f4msg_qnum\f1, \f4msg_lspid\f1, \f4msg_lrpid\f1,
\f4msg_stime\f1, and \f4msg_rtime\f1
are set to 0.
.IP
\f4msg_ctime\f1
is set to the current time.
.IP
\f4msg_qbytes\f1
is set to the system limit.
.PP
\f4msgget\fP
fails if one or more of the following are true:
.TP 15
\f4EACCES\fP
A message queue identifier exists for
.IR key ,
but operation permission [see
\f4intro\fP(2)]
as specified by the low-order 9 bits of
.I msgflg
would not be granted. 
.TP
\f4ENOENT\fP
A message queue identifier does not exist for
.I key
and
(\f2msgflg\f4&IPC_CREAT\f1)
is false.
.TP
\f4ENOSPC\fP
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.
.TP
\f4EEXIST\fP
A message queue identifier exists for
.I key
but (\f2msgflg\f4&IPC_CREAT\f1) and (\f2msgflg\f4&IPC_EXCL\f1)
are both true.
.SH SEE ALSO
\f4intro\fP(2), \f4msgctl\fP(2), \f4msgop\fP(2), \f4stdipc\fP(3C).
.SH "DIAGNOSTICS"
Upon successful completion,
a non-negative integer,
namely a message queue identifier, is returned.
Otherwise, a value of \-1 is returned and
\f4errno\fP
is set to indicate the error.
.\"	@(#)msgget.2	6.2 of 9/6/83
.Ee
