2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH mq_getattr 3 (date) "Linux man-pages (unreleased)"
8 mq_getattr, mq_setattr \- get/set message queue attributes
11 .RI ( librt ", " \-lrt )
14 .B #include <mqueue.h>
16 .BI "int mq_getattr(mqd_t " mqdes ", struct mq_attr *" attr );
17 .BI "int mq_setattr(mqd_t " mqdes ", const struct mq_attr *restrict " newattr ,
18 .BI " struct mq_attr *restrict " oldattr );
24 respectively retrieve and modify attributes of the message queue
25 referred to by the message queue descriptor
31 structure in the buffer pointed by
33 This structure is defined as:
38 long mq_flags; /* Flags: 0 or O_NONBLOCK */
39 long mq_maxmsg; /* Max. # of messages on queue */
40 long mq_msgsize; /* Max. message size (bytes) */
41 long mq_curmsgs; /* # of messages currently in queue */
48 field contains flags associated with the open message queue description.
49 This field is initialized when the queue is created by
51 The only flag that can appear in this field is
58 fields are set when the message queue is created by
62 field is an upper limit on the number of messages
63 that may be placed on the queue using
67 field is an upper limit on the size of messages
68 that may be placed on the queue.
69 Both of these fields must have a value greater than zero.
72 files that place ceilings on the values for these fields are described in
77 field returns the number of messages currently held in the queue.
80 sets message queue attributes using information supplied in the
82 structure pointed to by
84 The only attribute that can be modified is the setting of the
94 then the buffer that it points to is used to return an
96 structure that contains the same information that is returned by
103 return 0; on error, \-1 is returned, with
105 set to indicate the error.
109 The message queue descriptor specified in
114 .I newattr\->mq_flags
115 contained set bits other than
118 For an explanation of the terms used in this section, see
124 Interface Attribute Value
130 T} Thread safety MT-Safe
137 are library functions layered on top of the
138 .BR mq_getsetattr (2)
145 The program below can be used to show the default
149 values that are assigned to a message queue that is created with a call to
154 Here is an example run of the program:
158 $ \fB./a.out /testq\fP
159 Maximum # of messages on queue: 10
160 Maximum message size: 8192
164 Since Linux 3.5, the following
168 can be used to control the defaults:
174 $ \fBcat /proc/sys/fs/mqueue/msg_default\fP
176 $ \fBcat /proc/sys/fs/mqueue/msgsize_default\fP
182 .\" SRC BEGIN (mq_getattr.c)
188 #include <sys/stat.h>
191 #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
195 main(int argc, char *argv[])
201 fprintf(stderr, "Usage: %s mq\-name\en", argv[0]);
205 mqd = mq_open(argv[1], O_CREAT | O_EXCL, 0600, NULL);
206 if (mqd == (mqd_t) \-1)
209 if (mq_getattr(mqd, &attr) == \-1)
210 errExit("mq_getattr");
212 printf("Maximum # of messages on queue: %ld\en", attr.mq_maxmsg);
213 printf("Maximum message size: %ld\en", attr.mq_msgsize);
215 if (mq_unlink(argv[1]) == \-1)
216 errExit("mq_unlink");