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 */
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 */
};
|
Simple Program Example:
struct msqid_ds msg_info; if (msgctl(msgQid,IPC_STAT,&msg_info) == ERROR) { return ERROR; } else { return msg_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