msgctlのヘルプ・マニュアル
日本語 英語
msgctl --help
man msgctl
MSGCTL(2) Linux Programmer’s Manual MSGCTL(2)
名前
msgctl - メッセージ制御操作
書式
#include
#include
#include
int msgctl(int msqid, int cmd, struct msqid_ds *buf);
説明
msgctl() はメッセージ・キュー識別子 msqid で指定されたメッセージ・キュ
ー (message queue) に対して cmd で指定された制御操作を行なう。
msqid_ds データ構造体は で以下のように定義されている:
struct msqid_ds {
struct ipc_perm msg_perm; /* 所有権と許可 */
time_t msg_stime; /* 最後の msgsnd(2) の時刻 */
time_t msg_rtime; /* 最後の msgrcv(2) の時刻 */
time_t msg_ctime; /* 最後に変更が行われた時刻 */
unsigned long __msg_cbytes; /* キューにある現在のバイト数
(非標準) */
msgqnum_t msg_qnum; /* キューにある現在入っている
メッセージの数 */
msglen_t msg_qbytes; /* キューに許可されている
最大バイト数 */
pid_t msg_lspid; /* 最後の msgsnd(2) の PID */
pid_t msg_lrpid; /* 最後の msgrcv(2) の PID */
};
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; /* シーケンス番号 */
};
cmd として有効な値は:
IPC_STAT
msqid に関連づけられたメッセージ・キュー・データ構造体から、ポイ
ンタ buf が指し示す msqid_ds 構造体に情報をコピーする。呼び出 し
側はメッセージ・キューに対する読み込み許可を持っていなければなら
ない。
IPC_SET
ポインタ buf が指し示す msqid_ds 構造体のメンバーの値を、メッ セ
ー ジ ・キューに関連づけられたカーネル・データ構造体に書き込み、
msg_ctime メンバーも更新する。構造体のメンバーのうち、更新される
も の を 以 下 に 示 す: msg_qbytes, msg_perm.uid, msg_perm.gid,
msg_perm.mode (の下位 9 ビット)。呼び出したプロセスの実効ユー ザ
ID が 、メッセージ・キューの所有者 (msg_perm.uid) または作成者
(msg_perm.cuid) と一致するか、呼び出し元が特権を持たなければなら
ない。 msg_qbytes をシステム・パラメータの MSGMNB を超えて設定す
るには、適切な特権 (Linux では CAP_IPC_RESOURCE ケーパビリ テ ィ
(capability)) が必要である。
IPC_RMID
メッセージ・キューをただちに削除する。同時にその構造体の読み書き
の待ち状態にあったプロセスに通知する (エラーが返り、 errno が
EIDRM に設定される)。呼び出したプロセスが適切な特権を持っている
か、呼び出したプロセスの実効ユーザ ID がメッセージ・キューの作成
者か所有者の実効ユーザ ID でなければならない。
IPC_INFO (Linux 固有)
システム全体でのメッセージ・キューの制限とパラメータに関する情報
を、 buf が指す構造体に入れて返す。この構造体は msginfo 型である
(そのためキャストが必要である)。 msginfo は _GNU_SOURCE 機能検査
マクロが定義された場合に で以下のように定義される:
struct msginfo {
int msgpool; /* メッセージ・データの保持に使用される
バッファ・プールの大きさ (1024 バイト単位);
カーネル内では未使用 */
int msgmap; /* メッセージ・マップの最大エントリ数;
カーネル内では未使用 */
int msgmax; /* 一つのメッセージに書き込み可能な
最大バイト数 */
int msgmnb; /* 一つのキューに書き込み可能な最大バイト数;
(msgget(2) での) キュー作成中の msg_qbytes
の初期化に使用される */
int msgmni; /* メッセージ・キューの数の最大値 */
int msgssz; /* メッセージ・セグメントのサイズ;
カーネル内では未使用 */
int msgtql; /* システム上の全キューの最大メッセージ数;
カーネル内では未使用 */
unsigned short int msgseg;
/* 最大セグメント数; カーネル内では未使用 */
};
設定 msgmni , msgmax , msgmnb は /proc にある同じ名前のファイ ル
経由で変更可能である。詳しくは proc(5) を参照。
MSG_INFO (Linux 固有)
IPC_INFO のときと同じ情報を格納した msginfo 構造体を返す。但し、
以下のフィールドにはメッセージ・キューが消費しているシステム資源
に 関する情報が格納される点が異なる。 msgpool フィールドは現在シ
ステム上に存在するメッセージ・キューの数を返す。 msgmap フィール
ド は システム上の全てのキューに入っているメッセージ総数を返す。
msgtql フィールドはシステム上の全てのキューに入っている全メッ セ
ージの総バイト数を返す。
MSG_STAT (Linux 固有)
IPC_STAT と同じく msqid_ds 構造体を返す。但し、 msqid 引き数は、
キュー識別子ではなく、システム上の全てのメッセージ・キューに関す
る情報を管理するカーネルの内部配列へのインデックスである。
返り値
成 功 す る と 、 IPC_STAT, IPC_SET, IPC_RMID は 0 を返す。 IPC_INFO と
MSG_INFO 操作は、成功すると、全てのメッセージ・キューに関する情報を管理
し ているカーネルの内部配列の使用中エントリのインデックスのうち最大値を
返す (この情報は、システムの全てのメッセージ・キューに関する情報を取 得
す るために、 MSG_STAT 操作を繰り返し実行する際に使用できる)。 MSG_STAT
操作は、成功すると、 msqid で指定されたインデックスを持つメッセージ・キ
ューの識別子を返す。
エラーの場合は -1 を返し、 errno を適切に設定する。
エラー
失敗した場合、 errno は以下の値の中のどれか一つに設定される:
EACCES 引き数 cmd が IPC_STAT または MSG_STAT に等しいが、呼び出したプ
ロセスがメッセージ・キュー msqid に対する読み込み許可を持って お
らず、かつ CAP_IPC_OWNER ケーパビリティを持っていない。
EFAULT 引き数 cmd が IPC_SET か IPC_STAT で、ポインタ buf で指されてい
るアドレスがアクセス可能でない。
EIDRM メッセージ・キューが削除された。
EINVAL cmd または msqid に不正な値が設定された。もしくは、 MSG_STAT 操
作 の場合に、 msqid で指定されたインデックス値が現在未使用の配列
のスロットを参照いていた。
EPERM 引き数 cmd が IPC_SET か IPC_RMID であるが、呼び出したプロセスの
実 効 ユーザ ID がメッセージキューの (msg_perm.cuid として見つか
る) 作成者と (msg_perm.uid として見つかる) 所有者のいずれでも な
く 、かつ呼び出したプロセスに特権 (Linux では CAP_SYS_ADMIN ケー
パビリティ) がない。
準拠
SVr4, POSIX.1-2001.
注意
IPC_INFO, MSG_STAT, MSG_INFO 操作は、 ipcs(8) プログラムで割り当て済 の
資 源に関する情報を提供するために使用されている。将来、これらの操作は変
更されたり、 /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),
svipc(7)
Linux 2008-08-06 MSGCTL(2)
MSGCTL(2) Linux Programmer’s Manual MSGCTL(2)
NAME
msgctl - message control operations
SYNOPSIS
#include
#include
#include
int msgctl(int msqid, int cmd, struct msqid_ds *buf);
DESCRIPTION
msgctl() performs the control operation specified by cmd on the message
queue with identifier msqid.
The msqid_ds data structure is defined in as follows:
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 last change */
unsigned long __msg_cbytes; /* Current number of bytes in
queue (non-standard) */
msgqnum_t msg_qnum; /* Current number of messages
in queue */
msglen_t msg_qbytes; /* Maximum number of bytes
allowed in queue */
pid_t msg_lspid; /* PID of last msgsnd(2) */
pid_t msg_lrpid; /* PID of last msgrcv(2) */
};
The ipc_perm structure is defined in as follows (the high-
lighted fields are settable using IPC_SET):
struct ipc_perm {
key_t __key; /* Key supplied to msgget(2) */
uid_t uid; /* Effective UID of owner */
gid_t gid; /* Effective GID of owner */
uid_t cuid; /* Effective UID of creator */
gid_t cgid; /* Effective GID of creator */
unsigned short mode; /* Permissions */
unsigned short __seq; /* Sequence number */
};
Valid values for cmd are:
IPC_STAT
Copy information from the kernel data structure associated with
msqid into the msqid_ds structure pointed to by buf. The caller
must have read permission on the message queue.
IPC_SET
Write the values of some members of the msqid_ds structure
pointed to by buf to the kernel data structure associated with
this message queue, updating also its msg_ctime member. The
following members of the structure are updated: msg_qbytes,
msg_perm.uid, msg_perm.gid, and (the least significant 9 bits
of) msg_perm.mode. The effective UID of the calling process
must match the owner (msg_perm.uid) or creator (msg_perm.cuid)
of the message queue, or the caller must be privileged. Appro-
priate privilege (Linux: the CAP_IPC_RESOURCE capability) is
required to raise the msg_qbytes value beyond the system
parameter MSGMNB.
IPC_RMID
Immediately remove the message queue, awakening all waiting
reader and writer processes (with an error return and errno set
to EIDRM). The calling process must have appropriate privileges
or its effective user ID must be either that of the creator or
owner of the message queue.
IPC_INFO (Linux-specific)
Returns information about system-wide message queue limits and
parameters in the structure pointed to by buf. This structure
is of type msginfo (thus, a cast is required), defined in
if the _GNU_SOURCE feature test macro is defined:
struct msginfo {
int msgpool; /* Size in kibibytes of buffer pool
used to hold message data;
unused within kernel */
int msgmap; /* Maximum number of entries in message
map; unused within kernel */
int msgmax; /* Maximum number of bytes that can be
written in a single message */
int msgmnb; /* Maximum number of bytes that can be
written to queue; used to initialize
msg_qbytes during queue creation
(msgget(2)) */
int msgmni; /* Maximum number of message queues */
int msgssz; /* Message segment size;
unused within kernel */
int msgtql; /* Maximum number of messages on all queues
in system; unused within kernel */
unsigned short int msgseg;
/* Maximum number of segments;
unused within kernel */
};
The msgmni, msgmax, and msgmnb settings can be changed via /proc
files of the same name; see proc(5) for details.
MSG_INFO (Linux-specific)
Returns a msginfo structure containing the same information as
for IPC_INFO, except that the following fields are returned with
information about system resources consumed by message queues:
the msgpool field returns the number of message queues that cur-
rently exist on the system; the msgmap field returns the total
number of messages in all queues on the system; and the msgtql
field returns the total number of bytes in all messages in all
queues on the system.
MSG_STAT (Linux-specific)
Returns a msqid_ds structure as for IPC_STAT. However, the
msqid argument is not a queue identifier, but instead an index
into the kernel’s internal array that maintains information
about all message queues on the system.
RETURN VALUE
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
operations to obtain information about all queues on the system.) A
successful MSG_STAT operation returns the identifier of the queue whose
index was given in msqid.
On error, -1 is returned with errno indicating the error.
ERRORS
On failure, errno is set to one of the following:
EACCES The argument cmd is equal to IPC_STAT or MSG_STAT, but the call-
ing process does not have read permission on the message queue
msqid, and does not have the CAP_IPC_OWNER capability.
EFAULT The argument cmd has the value IPC_SET or IPC_STAT, but the
address pointed to by buf isn’t accessible.
EIDRM The message queue was removed.
EINVAL Invalid value for cmd or msqid. Or: for a MSG_STAT operation,
the index value specified in msqid referred to an array slot
that is currently unused.
EPERM The argument cmd has the value IPC_SET or IPC_RMID, but the
effective user ID of the calling process is not the creator (as
found in msg_perm.cuid) or the owner (as found in msg_perm.uid)
of the message queue, and the process is not privileged (Linux:
it does not have the CAP_SYS_ADMIN capability).
CONFORMING TO
SVr4, POSIX.1-2001.
NOTES
The IPC_INFO, MSG_STAT and MSG_INFO operations are used by the ipcs(8)
program to provide information on allocated resources. In the future
these may modified or moved to a /proc file system interface.
Various fields in the struct msqid_ds were typed as short under Linux
2.2 and have become long under Linux 2.4. To take advantage of this, a
recompilation under glibc-2.1.91 or later should suffice. (The kernel
distinguishes old and new calls by an IPC_64 flag in cmd.)
SEE ALSO
msgget(2), msgrcv(2), msgsnd(2), capabilities(7), mq_overview(7),
svipc(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-08-06 MSGCTL(2)