Getting Message Queuing information under Linux

Source: Internet
Author: User
Tags message queue

In the program you want to get the message queue length you can use the properties of Message Queuing This data structure: Requires # include <sys/msg.h>

/* one msqid structure for each queue on the system */structmsqid_ds {    structipc_perm msg_perm;    structmsg *msg_first;  /* first message on queue */    structmsg *msg_last;   /* last message in queue */    time_tmsg_stime;       /* last msgsnd time */    time_tmsg_rtime;       /* last msgrcv time */    time_tmsg_ctime;       /* last change time */    structwait_queue *wwait;    structwait_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 */};

Simple Program Example:

structmsqid_ds msg_info;if (msgctl(msgQid,IPC_STAT,&msg_info) == ERROR){    return ERROR;}else{    returnmsg_info.msg_qnum;}

Each parameter of the data structure is explained as follows: Msg_permAn instance of the IPC_PERM structure, which are defined for us in linux/ipc.h. This holds the permission information for the message queue, including the access permissions, and information about the C Reator of the queue (UID, etc). Msg_firstLink to the first message in the queue (the head of the list). Msg_lastLink to the last message in the queue (the tail of the list). Msg_stimeTimestamp (time_t), the last message, is sent to the queue. Msg_rtimeTimestamp of the last message retrieved from the queue. Msg_ctimeTimestamp of the Last "change" made to the "queue" (more on this later). wwaitand rwaitPointers into the kernel ' s Wait Queue. They is used if an operation on a message queue deems the process go to a sleep state (i.e. queue was full and the pro Cess is waiting for a opening). msg_cbytesTotal number of bytes residing in the queue (sum of the sizes of all messages). Msg_qnumNumber of messages currently in the queue. msg_qbytesMaximum number of bytes on the queue. Msg_lspidThe PID of the process who sent the last message. Msg_lrpidThe PID of the process who retrieved the last message.

Getting Message Queuing information under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.