mq_open err no 13 Permission denied
<p>I am running in to Permission issues while trying to create posix mq with mq_open() call. I did incorporate the change as mentioned here <a href="https://stackoverflow.com/questions/22780277/mq-open-eacces-permission-denied">mq_open Permission denied</a> I looked on other relevant post like this <a href="https://groups.google.com/forum/#!topic/comp.unix.programmer/hnTZf6aPpbE" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/comp.unix.programmer/hnTZf6aPpbE</a> but that also points to same thing.</p>

<p>Also while trying to compile I was running into error where mq calls were not identified and online it showed to compile by adding -lrt in gcc, post which was able to compile, mentioning it as I am not completely aware about rationale of it and didnt understand it by reading the post :)</p>

<p><strong>gcc server_mq.c -lrt -o server</strong></p>

<p><strong>error number is 13</strong> </p>

<p>Oh dear, something went wrong with mqd ! <strong>Permission denied</strong></p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;mqueue.h&gt;
#include &lt;errno.h&gt;
#include &lt;string.h&gt;

#include "client_server.h"

#define PATH "/tmp/servermq"

int main(void)
{
    mqd_t mqd;
    mode_t omask;
    omask = umask(0);
    int flags = O_RDWR | O_CREAT | O_EXCL;
    struct mq_attr attr, *attrp;

    attr.mq_maxmsg = 5;
    attr.mq_msgsize = 1024;

    attrp = &amp;attr;

    mqd = mq_open(PATH, flags, S_IRUSR | S_IWUSR | S_IWGRP, attrp);


    if (mqd == (mqd_t)-1)
    {
        printf("error number is %d \n ",errno);
        printf(" Oh dear, something went wrong with mqd ! %s\n", strerror(errno));
    }

    umask(omask);
    mq_close(mqd);
    mq_unlink(PATH);
    return 0;
}
</code></pre>