注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

NET START HERE

研究C/C++、网络/通信/协议编程、网络安全、软件安全

 
 
 

日志

 
 

linux编程获取消息队列当前占用字节数、消息个数  

2012-02-22 15:48:50|  分类: 技术探讨 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
在程序中想要获取消息队列长度可使用消息队列的属性这个数据结构:
/* 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 */
};
 
简单程序示例:
struct msqid_ds msg_info;       
if (msgctl(msgQid,IPC_STAT,&msg_info) == ERROR)
{
return ERROR;
}
else
{
return msg_info.msg_qnum;
}
 
数据结构各个参数详解如下:
msg_perm
An instance of the ipc_perm structure, which is defined for us in linux/ipc.h. This holds the permission information for the message queue, including the access permissions, and information about the creator of the queue (uid, etc).
msg_first
Link to the first message in the queue (the head of the list).
msg_last
Link to the last message in the queue (the tail of the list).
msg_stime
Timestamp (time_t) of the last message that was sent to the queue.
msg_rtime
Timestamp of the last message retrieved from the queue.
msg_ctime
Timestamp of the last ``change'' made to the queue (more on this later).
wwait
and
rwait
Pointers into the kernel's wait queue. They are used when an operation on a message queue deems the process go into a sleep state (i.e. queue is full and the process is waiting for an opening).
msg_cbytes
Total number of bytes residing on the queue (sum of the sizes of all messages).
msg_qnum
Number of messages currently in the queue.
msg_qbytes
Maximum number of bytes on the queue.
msg_lspid
The PID of the process who sent the last message.
msg_lrpid
The PID of the process who retrieved the last message.


 
  评论这张
 
阅读(1438)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017