Linux Message Queue Question!!!

Joined
Jul 28, 2010
Messages
2
Reaction score
0
#include <stdio.h>
#include <stdlib.h>
#include <linux/ipc.h>
#include <linux/msg.h>
#include <sys/types.h>
#include <wait.h>
#include <unistd.h>
#include <errno.h>
typedef struct
{
long mtype;
int veh_type;//1: car, 2: truck
int pid; //msg id
} msg;
main()
{ msg message;
message.mtype=1;
message.veh_type=0;
message.pid=0;

int qid=msgget(111,IPC_CREAT|0666);
msgsnd(qid,&message,sizeof(msg),0);

struct msqid_ds buf;

msgctl(qid,IPC_STAT,&buf);
int result=buf.msg_qbytes;
printf("%d\n",result);
msgctl(qid,IPC_RMID,0);
}


Hi every body:
I am facing a wired problem when I trying to figure out how message queue works

In the code above I simply want to send a message to an message queue. and output the number of messages in the queue. But the output is 0.....

Is there any one knows how to solve it...
Thanks very much!!! :D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top