problem with linux message queue

problem with linux message queue

Post by Michael Mandelber » Sat, 28 Oct 2000 22:58:51



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.

 
 
 

1. problem with linux message queue

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 A
 {
 long mtype;
 char mtext[20];
 }TM_MSGBUF;

 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

2. Microsoft Security Guru Leaves Post

3. Error Message of Message Queue

4. default & gettydefs man pages needed...help

5. HELP! encoding messages for message queues

6. xview3.0 not found

7. Deleting a message from a message queue??

8. Sideband addressing using nv-0.96

9. HELP!: encoding messages for message queues

10. HELP! encoding messages for message queues

11. how to see messages in message queue ...

12. message queue permission problem...

13. ipc-message queue problem