Please help me in creating a simple message queue and communicate through it.
I don't want to provide any attributes to my queue.
I have tried a small example, but it is not working
this is the code which I tried.
#include <stdio.h>
#include <fcntl.h> /* For O_* constants */
#include <sys/stat.h> /* For mode constants */
#include <mqueue.h>
int main()
{
// mqd_t mq_open(const char *name, int oflag, mode_t mode, struct mq_attr *attr);
mqd_t myQueue;
char msg_ptr[]="hai";
myQueue=mq_open("/myQueue1", O_RDWR|O_CREAT,0644, NULL);
if(myQueue<0)
printf("Failed");
mq_send(myQueue, msg_ptr, 4,1);
getchar();
return 0;
}
#include <stdio.h>
#include <fcntl.h> /* For O_* constants */
#include <sys/stat.h> /* For mode constants */
#include <mqueue.h>
int main()
{
mqd_t myQueue;
char msg_ptr[20];
myQueue=mq_open("/myQueue1", O_RDWR);
mq_receive(myQueue, msg_ptr, 4, 1);
printf("Received Message is %s\n",msg_ptr);
return 0;
}
|