Linux Message Queue Question

Joined
Jul 28, 2010
Messages
2
Reaction score
0
In the code below 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.....

anyone knows whats going on here......

Thanks very much!!! :D


#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);
}
 

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

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top