Check Unix Message Queue if empty or not

天涯浪子 提交于 2019-12-05 11:32:51

Just checking the amount (if any) of messages is done using the

msgctl() 

function, and examining the msqid_ds structure on return, the msg_qnum in this structure is the amount of messages in the queue. Here is a link with an example: msgctl example, it does more then you want, but after the msgctl() call you just have to check that field in the structure I mentioned above.

#include <sys/msg.h>

main() {
  int msqid = 2;
  int rc;
  struct msqid_ds buf;
  int num_messages;

  rc = msgctl(msqid, IPC_STAT, &buf);
  num_messages = buf.msg_qnum;
}

This example should do what you want, and only do what you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!