.\" t .\" Copyright (C) 2006 Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved. .\" Translated 2006-04-23, Akihiro MOTOKI .\" Updated 2008-11-09, Akihiro MOTOKI, LDP v3.13 .\" .TH MQ_GETATTR 3 2014\-10\-02 Linux "Linux Programmer's Manual" .SH 名前 mq_getattr, mq_setattr \- メッセージキューの属性を設定/取得する .SH 書式 .nf \fB#include \fP .sp \fBint mq_getattr(mqd_t \fP\fImqdes\fP\fB, struct mq_attr *\fP\fIattr\fP\fB);\fP \fBint mq_setattr(mqd_t \fP\fImqdes\fP\fB, const struct mq_attr *\fP\fInewattr\fP\fB,\fP \fB struct mq_attr *\fP\fIoldattr\fP\fB);\fP .fi .sp \fI\-lrt\fP でリンクする。 .SH 説明 \fBmq_getattr\fP() と \fBmq_setattr\fP() は、記述子 \fImqdes\fP で参照されるメッセージキューの属性の取得と変更をそれぞれ行う。 \fBmq_getattr\fP() は、 \fIattr\fP が指すバッファーに \fImq_attr\fP 構造体を格納して返す。この構造体は以下のように定義されている: .in +4n .nf struct mq_attr { long mq_flags; /* フラグ: 0 か O_NONBLOCK */ long mq_maxmsg; /* キューの最大メッセージ数 */ long mq_msgsize; /* 最大メッセージサイズ (バイト単位) */ long mq_curmsgs; /* キューに現在入っているメッセージ数 */ }; .fi .in .PP \fImq_flags\fP フィールドには、オープンメッセージキュー記述 (open message queue description) に関連付けられているフラグが格納される。 このフィールドは \fBmq_open\fP(3) でキューが作成される際に初期化される。 このフィールドに現れるフラグは \fBO_NONBLOCK\fP だけである。 \fImq_maxmsg\fP と \fImq_msgsize\fP フィールドは \fBmq_open\fP(3) でメッセージキューが作成される際にセットされる。 \fImq_maxmsg\fP フィールドは、 \fBmq_send\fP(3) を使ってキューに入れることができるメッセージ数の上限である。 \fImq_msgsize\fP フィールドは、キューに入れることができるメッセージの 上限サイズである。 これらのフィールドはどちらも 0 より大きな値でなければならない。 これらのフィールドに設定できる値の上限は \fI/proc\fP ファイルにより決まる。 \fI/proc\fP ファイルの詳細は \fBmq_overview\fP(7) に説明されている。 \fImq_curmsgs\fP フィールドはキューに現在格納されているメッセージ数を返す。 \fBmq_setattr\fP() は、 \fInewattr\fP が指す \fImq_attr\fP 構造体で与えられた情報を使って、メッセージキューの属性を設定する。 変更することができる属性は、 \fImq_flags\fP の \fBO_NONBLOCK\fP フラグの設定だけである。 \fInewattr\fP の他のフィールドは無視される。 \fIoldattr\fP フィールドが NULL 以外の場合、 \fBmq_getattr\fP() が返すのと同じ情報を格納した \fImq_attr\fP 構造体を \fIoldattr\fP が指すバッファーに入れて返す。 .SH 返り値 成功すると、 \fImq_getattr ()\fP と \fImq_setattr ()\fP は 0 を返す。エラーの場合、\-1 を返し、 \fIerrno\fP にエラーを示す値を設定する。 .SH エラー .TP \fBEBADF\fP \fImqdes\fP に指定されたディスクリプターが不正である。 .TP \fBEINVAL\fP \fInewattr\->mq_flags\fP に \fBO_NONBLOCK\fP 以外のビットがセットされていた。 .SH 属性 .SS "マルチスレッディング (pthreads(7) 参照)" 関数 \fBmq_getattr\fP() と \fBmq_setattr\fP() はスレッドセーフである。 .SH 準拠 POSIX.1\-2001. .SH 注意 Linux では、 \fBmq_getattr\fP() と \fBmq_setattr\fP() はライブラリ関数であり、 \fBmq_getsetattr\fP(2) システムコールを用いて実装されている。 .SH 例 下記のプログラムを使うと、 \fIattr\fP 引き数に NULL を指定して \fBmq_open\fP(3) を呼び出した際に作成されるメッセージキューに割り当てられるデフォルトの \fImq_maxmsg\fP と \fImq_msgsize\fP の値を表示できる。 このプログラムの実行例を以下に示す。 .in +4n .nf $ \fB./a.out /testq\fP Maximum # of messages on queue: 10 Maximum message size: 8192 .fi .in Linux 3.5 以降では、 (\fBmq_overview\fP(7) に説明がある) 以下の \fI/proc\fP ファイルを使ってデフォルト値を制御できる。 .in +4n .nf $ \fBuname \-sr\fP Linux 3.8.0 $ \fBcat /proc/sys/fs/mqueue/msg_default\fP 10 $ \fBcat /proc/sys/fs/mqueue/msgsize_default\fP 8192 .fi .in .SS プログラムのソース \& .nf #include #include #include #include #include #include #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e } while (0) int main(int argc, char *argv[]) { mqd_t mqd; struct mq_attr attr; if (argc != 2) { fprintf(stderr, "Usage: %s mq\-name\en", argv[0]); exit(EXIT_FAILURE); } mqd = mq_open(argv[1], O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, NULL); if (mqd == (mqd_t) \-1) errExit("mq_open"); if (mq_getattr(mqd, &attr) == \-1) errExit("mq_getattr"); printf("Maximum # of messages on queue: %ld\en", attr.mq_maxmsg); printf("Maximum message size: %ld\en", attr.mq_msgsize); if (mq_unlink(argv[1]) == \-1) errExit("mq_unlink"); exit(EXIT_SUCCESS); } .fi .SH 関連項目 \fBmq_close\fP(3), \fBmq_notify\fP(3), \fBmq_open\fP(3), \fBmq_receive\fP(3), \fBmq_send\fP(3), \fBmq_unlink\fP(3), \fBmq_overview\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。