Different Linux message queues have the same id?

Posted by Halo on Stack Overflow See other posts from Stack Overflow or by Halo
Published on 2010-03-07T14:52:27Z Indexed on 2010/03/13 8:35 UTC
Read the original article Hit count: 307

Filed under:
|
|
|

I open a mesage queue in a .c file, and upon success it says the message queue id is 3. While that program is still running, in another terminal I start another program (of another .c file), that creates a new message queue with a different mqd_t. But its id also appears as 3. Is this a problem?

server file goes like this:

void server(char* req_mq) {
struct mq_attr attr;
mqd_t mqdes;
struct request* msgptr;

int n;
char *bufptr;
int buflen;
pid_t apid;

//attr.mq_maxmsg = 300;
//attr.mq_msgsize = 1024;

mqdes = mq_open(req_mq, O_RDWR | O_CREAT, 0666, NULL);
if (mqdes == -1) {
    perror("can not create msg queue\n");
    exit(1);
}
printf("server mq created, mq id = %d\n", (int) mqdes);

and the client goes like:

void client(char* req_mq, int min, int max, char* dir_path_name, char* outfile) {

pid_t pid;

/* get the process id */
if ((pid = getpid()) < 0) {
    perror("unable to get client pid");
}

mqd_t mqd, dq;

char pfx[50] = DQ_PRFX;
char suffix[50]; //
sprintf(suffix, "%d", pid);
strcat(pfx, suffix);

dq = mq_open(pfx, O_RDWR | O_CREAT, 0666, NULL);
if (dq == -1) {
    perror("can not open data queue\n");
    exit(1);
}
printf("data queue created, mq id = %d\n", (int) dq);

mqd = mq_open(req_mq, O_RDWR);
if (mqd == -1) {
    perror("can not open msg queue\n");
    exit(1);
}

mqdes and dq seem to share the same id 3.

© Stack Overflow or respective owner

Related posts about c

    Related posts about message-queue