消息队列的使用

qq_36729593 2018-02-09 01:32:02
请教大神帮我看一下,一下是我读取消息队列的程序,为什么运行后消息队列还是有的,只是字节数变为0了?

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/types.h>

#define TEXT_SIZE 512

struct msgtype{
char contect[TEXT_SIZE];
char name[TEXT_SIZE];
char location[TEXT_SIZE];
};

struct msgbuf {
long mytype;
struct msgtype msg;
};

int main(void)
{
int mtype;
int msgid = msgget(1231, 0);
int n;
struct msgbuf ptr;


mtype = 2;

n = msgrcv(msgid, &ptr, sizeof(struct msgbuf) ,mtype, 0);

printf("name=%s\n",ptr.msg.name);
printf("contect=%s\n",ptr.msg.contect);
printf("location=%s\n",ptr.msg.location);

system("ipcs -q");

return 0 ;

}
...全文
1068 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
speed1313 2018-02-28
  • 打赏
  • 举报
回复
把你写消息队列的代码贴出来看一下,是不是你发送端发的消息内容为空啊
jklinux 2018-02-27
  • 打赏
  • 举报
回复
队列还是存在的,代码里没有删除队列,只是把队列里的内容(消息)接收而已
aabbabababaa 2018-02-17
  • 打赏
  • 举报
回复
这是什么语言?没用过消息队列,来学习下。。。

23,110

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧