LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   POSIX Message Queue (https://www.linuxquestions.org/questions/linux-newbie-8/posix-message-queue-4175473601/)

LinuxDreams 08-16-2013 06:48 AM

POSIX Message Queue
 
Hi

Can anyone tell me what is the third parameter in mq_open() prototype?


mqd_t mq_open("/myQuue", O_RDWR|O_CREATE, ?,NULL);

I don't want any attributes to be specified so I given NULL.

kooru 08-16-2013 06:56 AM

It should be ehe mode argument: specifies the permissions to be placed on the new queue (for example: 0640)

LinuxDreams 08-20-2013 05:35 AM

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;
}


All times are GMT -5. The time now is 03:16 PM.