MQ_OPEN(3) | Linux Programmer's Manual | MQ_OPEN(3) |
mq_open - メッセージキューをオープンする
#include <fcntl.h> /* For O_* constants */ #include <sys/stat.h> /* For mode constants */ #include <mqueue.h>
mqd_t mq_open(const char *name, int oflag); mqd_t mq_open(const char *name, int oflag, mode_t mode, struct mq_attr *attr);
-lrt でリンクする。
mq_open() は、新しい POSIX メッセージキューを作成するか、既存のキューを オープンする。キューは name で識別される。 name の構成の詳細については mq_overview (7) を参照。
oflag 引数には、関数呼び出しの操作を制御するフラグを指定する (oflag の値の定義は <fcntl.h> のインクルードにより得られる)。 oflag には、以下のうちいずれか一つを必ず指定しなければならない。
0 個以上の下記のフラグを、ビット単位の OR (論理和) で oflag に追加で指定できる。
oflag に O_CREAT を指定する場合、追加で 2つの引数を与える必要がある。 mode 引数は、新しいキューに適用される許可設定 (permission) を、 open(2) と同じように指定する (許可ビットのシンボル定義は <sys/stat.h> のインクルードにより得られる)。 許可設定はプロセスの umask でマスクされる。
The fields of the struct mq_attr pointed to attr specify the maximum number of messages and the maximum size of messages that the queue will allow. This structure is defined as follows:
struct mq_attr { long mq_flags; /* フラグ (mq_open() では無視される) */ long mq_maxmsg; /* キューの最大メッセージ数 */ long mq_msgsize; /* 最大メッセージサイズ (バイト単位) */ long mq_curmsgs; /* キューに現在入っているメッセージ数 (mq_open() では無視される) */ };
Only the mq_maxmsg and mq_msgsize fields are employed when calling mq_open(); the values in the remaining fields are ignored.
attr が NULL の場合、キューは実装で定義されたデフォルト属性で作成される。 Linux 3.5 以降では、2 つの /proc ファイルがあり、これらのデフォルト値を制御できる。 詳細は mq_overview(7) を参照。
成功すると、 mq_open() はメッセージキュー記述子 (message queue descriptor) を返す。 メッセージキュー記述子は他のメッセージキュー関連の関数で使用される。 エラーの場合、 mq_open() は (mqd_t) -1 を返し、 errno にエラーを示す値を設定する。
この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース | 属性 | 値 |
mq_open() | Thread safety | MT-Safe |
POSIX.1-2001, POSIX.1-2008.
The mq_open() library function is implemented on top of a system call of the same name. The library function performs the check that the name starts with a slash (/), giving the EINVAL error if it does not. The kernel system call expects name to contain no preceding slash, so the C library function passes name without the preceding slash (i.e., name+1) to the system call.
2.6.14 より前のカーネルには、 プロセスの umask が mode で指定された許可設定に適用されなかった。
mq_close(3), mq_getattr(3), mq_notify(3), mq_receive(3), mq_send(3), mq_unlink(3), mq_overview(7)
この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。
2020-08-13 | Linux |