每种类型的 IPC 对象都有一个由内核维护的内部数据结构。对于消息队列,这是msqid_ds结构体。内核为系统上创建的每个消息队列创建、存储和维护此结构体的一个实例。它在以下文件中定义:linux/msg.h如下所示
/* one msqid structure for each queue on the system */
struct msqid_ds {
struct ipc_perm msg_perm;
struct msg *msg_first; /* first message on queue */
struct msg *msg_last; /* last message in queue */
time_t msg_stime; /* last msgsnd time */
time_t msg_rtime; /* last msgrcv time */
time_t msg_ctime; /* last change time */
struct wait_queue *wwait;
struct wait_queue *rwait;
ushort msg_cbytes;
ushort msg_qnum;
ushort msg_qbytes; /* max number of bytes on queue */
ushort msg_lspid; /* pid of last msgsnd */
ushort msg_lrpid; /* last receive pid */
};
ipc_perm 的一个实例ipc_perm结构体,它在以下文件中为我们定义:linux/ipc.h。它保存消息队列的权限信息,包括访问权限以及关于队列创建者的信息(uid 等)。
链接到队列中的第一个消息(列表的头部)。
链接到队列中的最后一个消息(列表的尾部)。
时间戳 (time_t),表示最后一条发送到队列的消息的时间。
时间戳,表示最后一条从队列中检索的消息的时间。
时间戳,表示对队列进行的最后一次“更改”(稍后详细介绍)。
和
指向内核等待队列的指针。当消息队列上的操作认为进程应该进入睡眠状态时(即队列已满且进程正在等待空闲空间),它们会被使用。
队列上驻留的总字节数(所有消息大小的总和)。
当前队列中的消息数量。
队列上的最大字节数。
发送最后一条消息的进程的 PID。
检索最后一条消息的进程的 PID。