372 lines
7.2 KiB
HTML
372 lines
7.2 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of MSGGET</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>MSGGET</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-08-02<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
msgget - get a System V message queue identifier
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/sys/ipc.h">sys/ipc.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/sys/msg.h">sys/msg.h</A>></B>
|
|
|
|
<B>int msgget(key_t </B><I>key</I><B>, int </B><I>msgflg</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>msgget</B>()
|
|
|
|
system call returns the System V message queue identifier associated
|
|
with the value of the
|
|
<I>key</I>
|
|
|
|
argument.
|
|
It may be used either to obtain the identifier of a previously created
|
|
message queue (when
|
|
<I>msgflg</I>
|
|
|
|
is zero and
|
|
<I>key</I>
|
|
|
|
does not have the value
|
|
<B>IPC_PRIVATE</B>),
|
|
|
|
or to create a new set.
|
|
<P>
|
|
|
|
A new message queue is created if
|
|
<I>key</I>
|
|
|
|
has the value
|
|
<B>IPC_PRIVATE</B>
|
|
|
|
or
|
|
<I>key</I>
|
|
|
|
isn't
|
|
<B>IPC_PRIVATE</B>,
|
|
|
|
no message queue with the given key
|
|
<I>key</I>
|
|
|
|
exists, and
|
|
<B>IPC_CREAT</B>
|
|
|
|
is specified in
|
|
<I>msgflg</I>.
|
|
|
|
<P>
|
|
|
|
If
|
|
<I>msgflg</I>
|
|
|
|
specifies both
|
|
<B>IPC_CREAT</B>
|
|
|
|
and
|
|
<B>IPC_EXCL</B>
|
|
|
|
and a message queue already exists for
|
|
<I>key</I>,
|
|
|
|
then
|
|
<B>msgget</B>()
|
|
|
|
fails with
|
|
<I>errno</I>
|
|
|
|
set to
|
|
<B>EEXIST</B>.
|
|
|
|
(This is analogous to the effect of the combination
|
|
<B>O_CREAT | O_EXCL</B>
|
|
|
|
for
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2).)
|
|
|
|
<P>
|
|
|
|
Upon creation, the least significant bits of the argument
|
|
<I>msgflg</I>
|
|
|
|
define the permissions of the message queue.
|
|
These permission bits have the same format and semantics
|
|
as the permissions specified for the
|
|
<I>mode</I>
|
|
|
|
argument of
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2).
|
|
|
|
(The execute permissions are not used.)
|
|
<P>
|
|
|
|
If a new message queue is created,
|
|
then its associated data structure
|
|
<I>msqid_ds</I>
|
|
|
|
(see
|
|
<B><A HREF="/cgi-bin/man/man2html?2+msgctl">msgctl</A></B>(2))
|
|
|
|
is initialized as follows:
|
|
<DL COMPACT>
|
|
<DT id="1"><DD>
|
|
<I>msg_perm.cuid</I>
|
|
|
|
and
|
|
<I>msg_perm.uid</I>
|
|
|
|
are set to the effective user ID of the calling process.
|
|
<DT id="2"><DD>
|
|
<I>msg_perm.cgid</I>
|
|
|
|
and
|
|
<I>msg_perm.gid</I>
|
|
|
|
are set to the effective group ID of the calling process.
|
|
<DT id="3"><DD>
|
|
The least significant 9 bits of
|
|
<I>msg_perm.mode</I>
|
|
|
|
are set to the least significant 9 bits of
|
|
<I>msgflg</I>.
|
|
|
|
<DT id="4"><DD>
|
|
<I>msg_qnum</I>,
|
|
|
|
<I>msg_lspid</I>,
|
|
|
|
<I>msg_lrpid</I>,
|
|
|
|
<I>msg_stime</I>,
|
|
|
|
and
|
|
<I>msg_rtime</I>
|
|
|
|
are set to 0.
|
|
<DT id="5"><DD>
|
|
<I>msg_ctime</I>
|
|
|
|
is set to the current time.
|
|
<DT id="6"><DD>
|
|
<I>msg_qbytes</I>
|
|
|
|
is set to the system limit
|
|
<B>MSGMNB</B>.
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
If the message queue already exists the permissions are
|
|
verified, and a check is made to see if it is marked for
|
|
destruction.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
If successful, the return value will be the message queue identifier (a
|
|
nonnegative integer), otherwise -1
|
|
with
|
|
<I>errno</I>
|
|
|
|
indicating the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
On failure,
|
|
<I>errno</I>
|
|
|
|
is set to one of the following values:
|
|
<DL COMPACT>
|
|
<DT id="7"><B>EACCES</B>
|
|
|
|
<DD>
|
|
A message queue exists for
|
|
<I>key</I>,
|
|
|
|
but the calling process does not have permission to access the queue,
|
|
and does not have the
|
|
<B>CAP_IPC_OWNER</B>
|
|
|
|
capability in the user namespace that governs its IPC namespace.
|
|
<DT id="8"><B>EEXIST</B>
|
|
|
|
<DD>
|
|
<B>IPC_CREAT</B>
|
|
|
|
and
|
|
<B>IPC_EXCL</B>
|
|
|
|
were specified in
|
|
<I>msgflg</I>,
|
|
|
|
but a message queue already exists for
|
|
<I>key</I>.
|
|
|
|
<DT id="9"><B>ENOENT</B>
|
|
|
|
<DD>
|
|
No message queue exists for
|
|
<I>key</I>
|
|
|
|
and
|
|
<I>msgflg</I>
|
|
|
|
did not specify
|
|
<B>IPC_CREAT</B>.
|
|
|
|
<DT id="10"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
A message queue has to be created but the system does not have enough
|
|
memory for the new data structure.
|
|
<DT id="11"><B>ENOSPC</B>
|
|
|
|
<DD>
|
|
A message queue has to be created but the system limit for the maximum
|
|
number of message queues
|
|
(<B>MSGMNI</B>)
|
|
|
|
would be exceeded.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SVr4.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The inclusion of
|
|
<I><<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></I>
|
|
|
|
and
|
|
<I><<A HREF="file:///usr/include/sys/ipc.h">sys/ipc.h</A>></I>
|
|
|
|
isn't required on Linux or by any version of POSIX.
|
|
However,
|
|
some old implementations required the inclusion of these header files,
|
|
and the SVID also documented their inclusion.
|
|
Applications intended to be portable to such old systems may need
|
|
to include these header files.
|
|
|
|
|
|
<P>
|
|
|
|
<B>IPC_PRIVATE</B>
|
|
|
|
isn't a flag field but a
|
|
<I>key_t</I>
|
|
|
|
type.
|
|
If this special value is used for
|
|
<I>key</I>,
|
|
|
|
the system call ignores everything but the least significant 9 bits of
|
|
<I>msgflg</I>
|
|
|
|
and creates a new message queue (on success).
|
|
<P>
|
|
|
|
The following is a system limit on message queue resources affecting a
|
|
<B>msgget</B>()
|
|
|
|
call:
|
|
<DL COMPACT>
|
|
<DT id="12"><B>MSGMNI</B>
|
|
|
|
<DD>
|
|
System-wide limit on the number of message queues.
|
|
Before Linux 3.19,
|
|
|
|
the default value for this limit was calculated using a formula
|
|
based on available system memory.
|
|
Since Linux 3.19, the default value is 32,000.
|
|
On Linux, this limit can be read and modified via
|
|
<I>/proc/sys/kernel/msgmni</I>.
|
|
|
|
</DL>
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Linux notes</H3>
|
|
|
|
Until version 2.3.20, Linux would return
|
|
<B>EIDRM</B>
|
|
|
|
for a
|
|
<B>msgget</B>()
|
|
|
|
on a message queue scheduled for deletion.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
The name choice
|
|
<B>IPC_PRIVATE</B>
|
|
|
|
was perhaps unfortunate,
|
|
<B>IPC_NEW</B>
|
|
|
|
would more clearly show its function.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+msgctl">msgctl</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+msgrcv">msgrcv</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+msgsnd">msgsnd</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ftok">ftok</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+mq_overview">mq_overview</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+sysvipc">sysvipc</A></B>(7)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="13"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="14"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="15"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="16"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="17"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="18"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="19"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="20"><A HREF="#lbAI">Linux notes</A><DD>
|
|
</DL>
|
|
<DT id="21"><A HREF="#lbAJ">BUGS</A><DD>
|
|
<DT id="22"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="23"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:33 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|