Sorry if this belongs elsewhere. If so, I'd appreciate a pointer.
I am trying to use the IPC message queue on Redhat 6.2. Here's my code
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
#define TM_MSGQ_KEY 1000
typedef struct TM_MSGBUF
{
long mtype;
char mtext[20];
}a;
int main()
{
int tm_msqId = msgget( TM_MSGQ_KEY, 0666 | IPC_CREAT );
TM_MSGBUF bufsnd={100,"Hope this works"}, bufrcv;
bufsnd.mtype = 100;
printf("send buffer type = %d\n",bufsnd.mtype);
printf("send buffer data = %s\n\n\n",bufsnd.mtext);
msgsnd(tm_msqId, (struct msgbuf *)&bufsnd, sizeof(bufsnd), 0);
msgrcv(tm_msqId,(struct msgbuf *)&bufrcv,sizeof(bufrcv), 0, 0);
printf("send buffer type = %d\n",bufsnd.mtype);
printf("send buffer data = %s\n\n\n",bufsnd.mtext);
printf("receive buffer type = %d\n",bufrcv.mtype);
printf("receive buffer data = %s\n\n\n",bufrcv.mtext);
}
And here's the output:
send buffer type = 100
send buffer data = Hope this works
send buffer type = 0
send buffer data = Hope this works
receive buffer type = 100
receive buffer data = Hope this works
The problem is that the message type in bufsnd has been corrupted. Any
ideas what's going on here?
Thanks
Michael Mandelberg
Sent via Deja.com http://www.deja.com/
Before you buy.