Unix-system-calls-msgctl

提供:Dev Guides
移動先:案内検索

[top]#

[[File:]]

[[File:]]

|Web |This Site

  • 初心者向けのUnix *
  • 高度なUnix *

選択した読書

Copyright©2014 by finddevguides

  Home     References     Discussion Forums     About TP  

msgctl()-Unix、Linuxシステムコール

[[File:]] image :http://www.finddevguides.com/images/next.gif [next] image:http://www.finddevguides.com/add- this.gif [AddThisソーシャルブックマークボタン]

広告

NAME

msgctl-メッセージ制御操作

概要

#include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h>
*int msgctl(int* __msqid __ **、** *int* __cmd __ **、** * *struct msqid_ds* * *__ buf __* ); *

説明

*msgctl* ()は、識別子_msqid_を持つメッセージキューに対して_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()*/ time_t msg_rtime; /*Time of last msgrcv()*/ 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()*/ pid_t msg_lrpid; /*PID of last msgrcv()*/ };

_ipc_perm_構造は、次のように<sys/ipc.h>で定義されています(強調表示されたフィールドは、 IPC_SET を使用して設定可能です)。

struct ipc_perm { key_t key; /*Key supplied to msgget()*/ 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*/ };

_cmd_の有効な値は次のとおりです。

Tag

説明

*IPC_STAT*

_msqid_に関連付けられているカーネルデータ構造から、_buf_が指す_msqid_ds_構造に情報をコピーします。 呼び出し元には、メッセージキューの読み取りアクセス許可が必要です。

*IPC_SET*

buf_が指す_msqid_ds_構造体の一部のメンバーの値を、このメッセージキューに関連付けられたカーネルデータ構造体に書き込み、その_msg_ctime_メンバーも更新します。 構造体の次のメンバーが更新されます:_msg_qbytes _、 msg_perm.uid msg_perm.gid_、および(の最下位9ビット)msg_perm.mode。 呼び出しプロセスの実効UIDは、メッセージキューの所有者(msg_perm.uid)または作成者(msg_perm.cuid)と一致する必要があります。または、呼び出し元に特権が必要です。 システムパラメータ MSGMNB を超えて_msg_qbytes_値を上げるには、適切な特権(Linux: CAP_IPC_RESOURCE 機能)が必要です。

*IPC_RMID*

メッセージキューをすぐに削除し、すべての待機中のリーダーおよびライタープロセスを呼び起こします(エラーが返され、_errno_が EIDRM に設定されます)。 呼び出しプロセスには適切な特権が必要です。または、その有効なユーザーIDはメッセージキューの作成者または所有者のいずれかでなければなりません。

*IPC_INFO* (Linux固有)

buf_が指す構造内のシステム全体のメッセージキュー制限とパラメーターに関する情報を返します。 この構造は_msginfo_型であり(したがって、キャストが必要です)、 GNU_SOURCE機能テストマクロが定義されている場合は_ <sys/msg.h> _で定義されます。

struct msginfo { int msgpool;/*Size in bytes of buffer pool used to hold message data; unused*/ int msgmap; /*Max. # of entries in message map; unused*/ int msgmax; /*Max. # of bytes that can be written in a single message*/ int msgmnb; /*Max. # of bytes that can be written to queue; used to initialize msg_qbytes during queue creation (msgget())*/ int msgmni; /*Max. # of message queues*/ int msgssz; /*Message segment size; unused*/ int msgtql; /*Max. # of messages on all queues in system; unused*/ unsigned short int msgseg; /*Max. # of segments; unused*/ };

msgmni _、 msgmax_、および_msgmnb_の設定は、同じ名前の_/proc_ファイルを介して変更できます。詳細については、 proc (5)を参照してください。

*MSG_INFO* (Linux固有)
*IPC_INFO* と同じ情報を含む_msginfo_構造体を返します。ただし、メッセージキューによって消費されるシステムリソースに関する情報とともに以下のフィールドが返される点が異なります。 _msgmap_フィールドは、システム上のすべてのキュー内のメッセージの総数を返します。 _msgtql_フィールドは、システム上のすべてのキュー内のすべてのメッセージの合計バイト数を返します。
*MSG_STAT* (Linux固有)
*IPC_STAT* の場合の_msqid_ds_構造体を返します。 ただし、_msqid_引数はキュー識別子ではなく、システム上のすべてのメッセージキューに関する情報を保持するカーネルの内部配列へのインデックスです。

返り値

成功すると、 IPC_STATIPC_SET 、および IPC_RMID は0を返します。 IPC_INFO または MSG_INFO 操作が成功すると、すべてのメッセージキューに関する情報を記録しているカーネルの内部配列で最も使用されているエントリのインデックスが返されます。 (この情報は、繰り返しの MSG_STAT 操作で使用して、システム上のすべてのキューに関する情報を取得できます。) MSG_STAT 操作が成功すると、_msqid_でインデックスが指定されたキューの識別子が返されます。

エラー時には、エラーを示す_errno_とともに-1が返されます。

エラー

失敗すると、_errno_は次のいずれかに設定されます。

Tag Description
*EACCES * The argument cmd is equal to* IPC_STAT or MSG_STAT*, but the calling 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).

ノート

*IPC_INFO* 、 *MSG_STAT* 、および *MSG_INFO* 操作は、割り当てられたリソースに関する情報を提供するために *ipcs* (8)プログラムによって使用されます。 将来、これらは/procファイルシステムインターフェイスに変更または移動される可能性があります。

_struct msqid_ds_のさまざまなフィールドは、Linux 2.2ではショートでしたが、Linux 2.4ではロングになりました。 これを利用するには、glibc-2.1.91以降での再コンパイルで十分です。 (カーネルは、_cmd_のIPC_64フラグによって古い呼び出しと新しい呼び出しを区別します。)

準拠

SVr4、POSIX.1-2001。

関連項目

[[File:]] image :http://www.finddevguides.com/images/next.gif [next] [[File:]]

広告

  
Advertisements