352 lines
8.9 KiB
HTML
352 lines
8.9 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of MQ_GETATTR</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>MQ_GETATTR</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<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>
|
|
|
|
mq_getattr, mq_setattr - get/set message queue attributes
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/mqueue.h">mqueue.h</A>></B>
|
|
|
|
<B>int mq_getattr(mqd_t </B><I>mqdes</I><B>, struct mq_attr *</B><I>attr</I><B>);</B>
|
|
|
|
<B>int mq_setattr(mqd_t </B><I>mqdes</I><B>, const struct mq_attr *</B><I>newattr</I><B>,</B>
|
|
<B> struct mq_attr *</B><I>oldattr</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
Link with <I>-lrt</I>.
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>mq_getattr</B>()
|
|
|
|
and
|
|
<B>mq_setattr</B>()
|
|
|
|
respectively retrieve and modify attributes of the message queue
|
|
referred to by the message queue descriptor
|
|
<I>mqdes</I>.
|
|
|
|
<P>
|
|
|
|
<B>mq_getattr</B>()
|
|
|
|
returns an
|
|
<I>mq_attr</I>
|
|
|
|
structure in the buffer pointed by
|
|
<I>attr</I>.
|
|
|
|
This structure is defined as:
|
|
<P>
|
|
|
|
|
|
|
|
struct mq_attr {
|
|
<BR> long mq_flags; /* Flags: 0 or O_NONBLOCK */
|
|
<BR> long mq_maxmsg; /* Max. # of messages on queue */
|
|
<BR> long mq_msgsize; /* Max. message size (bytes) */
|
|
<BR> long mq_curmsgs; /* # of messages currently in queue */
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>mq_flags</I>
|
|
|
|
field contains flags associated with the open message queue description.
|
|
This field is initialized when the queue is created by
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_open">mq_open</A></B>(3).
|
|
|
|
The only flag that can appear in this field is
|
|
<B>O_NONBLOCK</B>.
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>mq_maxmsg</I>
|
|
|
|
and
|
|
<I>mq_msgsize</I>
|
|
|
|
fields are set when the message queue is created by
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_open">mq_open</A></B>(3).
|
|
|
|
The
|
|
<I>mq_maxmsg</I>
|
|
|
|
field is an upper limit on the number of messages
|
|
that may be placed on the queue using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_send">mq_send</A></B>(3).
|
|
|
|
The
|
|
<I>mq_msgsize</I>
|
|
|
|
field is an upper limit on the size of messages
|
|
that may be placed on the queue.
|
|
Both of these fields must have a value greater than zero.
|
|
Two
|
|
<I>/proc</I>
|
|
|
|
files that place ceilings on the values for these fields are described in
|
|
<B><A HREF="/cgi-bin/man/man2html?7+mq_overview">mq_overview</A></B>(7).
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>mq_curmsgs</I>
|
|
|
|
field returns the number of messages currently held in the queue.
|
|
<P>
|
|
|
|
<B>mq_setattr</B>()
|
|
|
|
sets message queue attributes using information supplied in the
|
|
<I>mq_attr</I>
|
|
|
|
structure pointed to by
|
|
<I>newattr</I>.
|
|
|
|
The only attribute that can be modified is the setting of the
|
|
<B>O_NONBLOCK</B>
|
|
|
|
flag in
|
|
<I>mq_flags</I>.
|
|
|
|
The other fields in
|
|
<I>newattr</I>
|
|
|
|
are ignored.
|
|
If the
|
|
<I>oldattr</I>
|
|
|
|
field is not NULL,
|
|
then the buffer that it points to is used to return an
|
|
<I>mq_attr</I>
|
|
|
|
structure that contains the same information that is returned by
|
|
<B>mq_getattr</B>().
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success
|
|
<B>mq_getattr</B>()
|
|
|
|
and
|
|
<B>mq_setattr</B>()
|
|
|
|
return 0; on error, -1 is returned, with
|
|
<I>errno</I>
|
|
|
|
set to indicate the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>EBADF</B>
|
|
|
|
<DD>
|
|
The message queue descriptor specified in
|
|
<I>mqdes</I>
|
|
|
|
is invalid.
|
|
<DT id="2"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
<I>newattr->mq_flags</I>
|
|
|
|
contained set bits other than
|
|
<B>O_NONBLOCK</B>.
|
|
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>mq_getattr</B>(),
|
|
|
|
<B>mq_setattr</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
On Linux,
|
|
<B>mq_getattr</B>()
|
|
|
|
and
|
|
<B>mq_setattr</B>()
|
|
|
|
are library functions layered on top of the
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mq_getsetattr">mq_getsetattr</A></B>(2)
|
|
|
|
system call.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The program below can be used to show the default
|
|
<I>mq_maxmsg</I>
|
|
|
|
and
|
|
<I>mq_msgsize</I>
|
|
|
|
values that are assigned to a message queue that is created with a call to
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_open">mq_open</A></B>(3)
|
|
|
|
in which the
|
|
<I>attr</I>
|
|
|
|
argument is NULL.
|
|
Here is an example run of the program:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>./a.out /testq</B>
|
|
Maximum # of messages on queue: 10
|
|
Maximum message size: 8192
|
|
|
|
|
|
<P>
|
|
|
|
Since Linux 3.5, the following
|
|
<I>/proc</I>
|
|
|
|
files (described in
|
|
<B><A HREF="/cgi-bin/man/man2html?7+mq_overview">mq_overview</A></B>(7))
|
|
|
|
can be used to control the defaults:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>uname -sr</B>
|
|
Linux 3.8.0
|
|
$ <B>cat /proc/sys/fs/mqueue/msg_default</B>
|
|
10
|
|
$ <B>cat /proc/sys/fs/mqueue/msgsize_default</B>
|
|
8192
|
|
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Program source</H3>
|
|
|
|
|
|
|
|
#include <<A HREF="file:///usr/include/mqueue.h">mqueue.h</A>>
|
|
#include <<A HREF="file:///usr/include/sys/stat.h">sys/stat.h</A>>
|
|
#include <<A HREF="file:///usr/include/fcntl.h">fcntl.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>>
|
|
<P>
|
|
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
|
|
<BR> } while (0)
|
|
<P>
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
<BR> mqd_t mqd;
|
|
<BR> struct mq_attr attr;
|
|
<P>
|
|
<BR> if (argc != 2) {
|
|
<BR> fprintf(stderr, "Usage: %s mq-name\n", argv[0]);
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> mqd = mq_open(argv[1], O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, NULL);
|
|
<BR> if (mqd == (mqd_t) -1)
|
|
<BR> errExit("mq_open");
|
|
<P>
|
|
<BR> if (mq_getattr(mqd, &attr) == -1)
|
|
<BR> errExit("mq_getattr");
|
|
<P>
|
|
<BR> printf("Maximum # of messages on queue: %ld\n", attr.mq_maxmsg);
|
|
<BR> printf("Maximum message size: %ld\n", attr.mq_msgsize);
|
|
<P>
|
|
<BR> if (mq_unlink(argv[1]) == -1)
|
|
<BR> errExit("mq_unlink");
|
|
<P>
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_close">mq_close</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_notify">mq_notify</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_open">mq_open</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_receive">mq_receive</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_send">mq_send</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mq_unlink">mq_unlink</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+mq_overview">mq_overview</A></B>(7)
|
|
|
|
<A NAME="lbAM"> </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="3"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="7"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="8"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="9"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="10"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="11"><A HREF="#lbAJ">EXAMPLE</A><DD>
|
|
<DL>
|
|
<DT id="12"><A HREF="#lbAK">Program source</A><DD>
|
|
</DL>
|
|
<DT id="13"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="14"><A HREF="#lbAM">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:48 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|