Skip to content

Latest commit

 

History

History
25 lines (25 loc) · 1.12 KB

消息队列.md

File metadata and controls

25 lines (25 loc) · 1.12 KB

消息队列

消息的链式队列。
重要的数据结构

msqid_ds

//位置/usr/include/linux/msg.h
struct msqid_ds {
	struct ipc_perm msg_perm;
	struct msg *msg_first;		/* 指向消息头 */
	struct msg *msg_last;		/* 指向消息尾 */
	__kernel_time_t msg_stime;	/* 最近msgsnd(发送消息)时间 */
	__kernel_time_t msg_rtime;	/* 最近msgrcv(接收消息)时间 */
	__kernel_time_t msg_ctime;	/* 最近修改时间 */
	unsigned long  msg_lcbytes;	/* Reuse junk fields for 32 bit */
	unsigned long  msg_lqbytes;	/* ditto */
	unsigned short msg_cbytes;	/* 当前队列的字节数 */
	unsigned short msg_qnum;	/* 当前队列中消息个数 */
	unsigned short msg_qbytes;	/* 队列最大字节数 */
	__kernel_ipc_pid_t msg_lspid;	/* 最近msgsnd的pid */
	__kernel_ipc_pid_t msg_lrpid;	/* 最近receive的pid */
};

key值与ID值

每一个IPC机制都有一个ID,只有ID值相同才能传递数据。它的类型是key_t(int),但是设置任意数字为key值有违软件设计的思想。所以Linux提供了函数ftok来创建key值,以文件为参数,提高了与文件的关联度。