#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!!!
#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!!!