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!!!
#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);
}
anyone knows whats going on here......
Thanks very much!!!
#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);
}