消息队列的使用
请教大神帮我看一下,一下是我读取消息队列的程序,为什么运行后消息队列还是有的,只是字节数变为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 ;
}