2.消息隊列的三個數據結構
linux內核採用的結構msqid_ds管理消息隊列
- struct msqid_ds
- {
- struct ipc_perm msg_perm; //消息隊列訪問權限
- struct msg *msg_first; //指向第一個消息的指針
- struct msg *msg_last; //指向最後一個消息的指針
- ulong msg_cbytes; //消息隊列當前的字節數
- ulong msg_qnum; //消息隊列當前的消息個數
- ulong msg_qbytes; //消息隊列可容納的最大字節數
- pid_t msg_lsqid; //最後發送消息的進程號ID
- pid_t msg_lrqid; //最後接收消息的進程號ID
- time_t msg_stime; //最後發送消息的時間
- time_t msg_rtime; //最後接收消息的時間
- time_t msg_ctime; //最近修改消息隊列的時間
- };
linux內核採用的結構msg_queue來描述消息隊列
- struct msg_queue {
- structkern_ipc_perm q_perm;
- time_tq_stime; /* last msgsndtime */
- time_tq_rtime; /* last msgrcvtime */
- time_tq_ctime; /* last changetime */
- unsignedlong q_cbytes; /* current number of bytes on queue*/
- unsignedlong q_qnum; /* number of messages inqueue */
- unsignedlong q_qbytes; /* max number of bytes on queue */
- pid_tq_lspid; /* pid oflast msgsnd */
- pid_tq_lrpid; /* lastreceive pid */
- structlist_head q_messages;
- structlist_head q_receivers;
- structlist_head q_senders;
- };
syetem V IPC 爲每一個IPC結構設置了一個ipc_perm結構,該結構規定了許可權和所有者
- struct ipc_perm
- {
- key_t key; //調用shmget()時給出的關鍵字
- uid_t uid; //共享內存所有者的有效用戶ID
- gid_t gid; //共享內存所有者所屬組的有效組ID
- uid_t cuid; //共享內存創建 者的有效用戶ID
- gid_t cgid; //共享內存創建者所屬組的有效組ID
- unsigned short mode; //Permissions + SHM_DEST和SHM_LOCKED標誌
- unsignedshort seq; //序列號
- };