MSGCTL(2) | Linux Programmer's Manual | MSGCTL(2) |
msgctl - System V メッセージ制御操作
#include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h>
int msgctl(int msqid, int cmd, struct msqid_ds *buf);
msgctl() はメッセージキュー識別子 msqid で指定された System V メッセージキュー (message queue) に対して cmd で指定された制御操作を行なう。
msqid_ds データ構造体は <sys/msg.h> で以下のように定義されている:
struct msqid_ds { struct ipc_perm msg_perm; /* Ownership and permissions */ time_t msg_stime; /* Time of last msgsnd(2) */ time_t msg_rtime; /* Time of last msgrcv(2) */ time_t msg_ctime; /* Time of creation or last modification by msgctl() */ unsigned long msg_cbytes; /* # of bytes in queue */ msgqnum_t msg_qnum; /* # number of messages in queue */ msglen_t msg_qbytes; /* Maximum # of bytes in queue */ pid_t msg_lspid; /* PID of last msgsnd(2) */ pid_t msg_lrpid; /* PID of last msgrcv(2) */ };
msgid_ds 構造体のフィールドは以下の通りである:
ipc_perm 構造体は以下のように定義されている (強調されたフィールドは IPC_SET を使って設定可能である):
struct ipc_perm { key_t __key; /* msgget(2) に与えるキー */ uid_t uid; /* 所有者の実効 UID */ gid_t gid; /* 所有者の実効 GID */ uid_t cuid; /* 作成者の実効 UID */ gid_t cgid; /* 作成者の実効 GID */ unsigned short mode; /* 許可 */ unsigned short __seq; /* シーケンス番号 */ };
The least significant 9 bits of the mode field of the ipc_perm structure define the access permissions for the message queue. The permission bits are as follows:
0400 | ユーザーによる読み出し |
0200 | ユーザーによる書き込み |
0040 | グループによる読み出し |
0020 | グループによる書き込み |
0004 | 他人 (others) による読み出し |
0002 | 他人 (others) による書き込み |
ビット 0100, 0010, 0001 (実行ビット) をシステムは使用しない。
cmd として有効な値は:
struct msginfo { int msgpool; /* メッセージデータの保持に使用される バッファープールの大きさ (1024 バイト単位); カーネル内では未使用 */ int msgmap; /* メッセージマップの最大エントリー数; カーネル内では未使用 */ int msgmax; /* 一つのメッセージに書き込み可能な 最大バイト数 */ int msgmnb; /* 一つのキューに書き込み可能な最大バイト数; (msgget(2) での) キュー作成中の msg_qbytes の初期化に使用される */ int msgmni; /* メッセージキューの数の最大値 */ int msgssz; /* メッセージセグメントのサイズ; カーネル内では未使用 */ int msgtql; /* システム上の全キューの最大メッセージ数; カーネル内では未使用 */ unsigned short msgseg; /* 最大セグメント数; カーネル内では未使用 */ };
On success, IPC_STAT, IPC_SET, and IPC_RMID return 0. A successful IPC_INFO or MSG_INFO operation returns the index of the highest used entry in the kernel's internal array recording information about all message queues. (This information can be used with repeated MSG_STAT or MSG_STAT_ANY operations to obtain information about all queues on the system.) A successful MSG_STAT or MSG_STAT_ANY operation returns the identifier of the queue whose index was given in msqid.
エラーの場合は -1 を返し、 errno を適切に設定する。
失敗した場合、 errno は以下の値の中のどれか一つに設定される:
POSIX.1-2001, POSIX.1-2008, SVr4.
Linux や POSIX の全てのバージョンでは、 <sys/types.h> と <sys/ipc.h> のインクルードは必要ない。しかしながら、いくつかの古い実装ではこれらのヘッダーファイルのインクルードが必要であり、 SVID でもこれらのインクルードをするように記載されている。このような古いシステムへの移植性を意図したアプリケーションではこれらのファイルをインクルードする必要があるかもしれない。
IPC_INFO, MSG_STAT, MSG_INFO 操作は、 ipcs(1) プログラムで割り当て済の資源に関する情報を提供するために 使用されている。将来、これらの操作は変更されたり、 /proc ファイルシステムのインターフェースに移動されるかもしれない。
struct msqid_ds 内の多くのフィールドは、 Linux 2.2 では short だったが、Linux 2.4 では long になった。 この利点を生かすには、glibc-2.1.91 以降の環境下で 再コンパイルすれば十分である。 (カーネルは新しい形式の呼び出しと古い形式の呼び出しを cmd 内の IPC_64 フラグで区別する。)
msgget(2), msgrcv(2), msgsnd(2), capabilities(7), mq_overview(7), sysvipc(7)
この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。
2020-11-01 | Linux |