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
138 are library functions layered on top of the
139 .BR mq_getsetattr (2)
146 The program below can be used to show the default
150 values that are assigned to a message queue that is created with a call to
155 Here is an example run of the program:
159 $ \fB./a.out /testq\fP
160 Maximum # of messages on queue: 10
161 Maximum message size: 8192
165 Since Linux 3.5, the following
169 can be used to control the defaults:
175 $ \fBcat /proc/sys/fs/mqueue/msg_default\fP
177 $ \fBcat /proc/sys/fs/mqueue/msgsize_default\fP
183 .\" SRC BEGIN (mq_getattr.c)
189 #include <sys/stat.h>
192 #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
196 main(int argc, char *argv[])
202 fprintf(stderr, "Usage: %s mq\-name\en", argv[0]);
206 mqd = mq_open(argv[1], O_CREAT | O_EXCL, 0600, NULL);
207 if (mqd == (mqd_t) \-1)
210 if (mq_getattr(mqd, &attr) == \-1)
211 errExit("mq_getattr");
213 printf("Maximum # of messages on queue: %ld\en", attr.mq_maxmsg);
214 printf("Maximum message size: %ld\en", attr.mq_msgsize);
216 if (mq_unlink(argv[1]) == \-1)
217 errExit("mq_unlink");