1 year ago
#334598
Engineer999
Using multiple inter-process communication queues in C
I am trying to use multiple different message queues in C for communicating between different processes on Linux. I use systemd.
See my code below for one process. Why is it that msgid1
and msgid2
are the exact same value in this case?
Doesn't this then mean that the queues are the same?
I would expect that I am creating different queues here.
#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/msg.h>
int main()
{
struct buffer1
{
long mesg_type;
int num;
}message1;
struct buffer2
{
long mesg_type;
char text[20];
}message2;
key_t key1;
key_t key2;
int msgid1;
int msgid2;
// ftok to generate unique key
key1 = ftok("test1",1);
key2 = ftok("test2",2);
msgid1 = msgget(key1, 0666 | IPC_CREAT);
msgid2 = msgget(key2, 0666 | IPC_CREAT);
// printf("%d %d", msgid1 , msgid2 ); -- msgid1 and msgid2 are the same values
//msgrcv(msgid1, &message1, sizeof(message1), 1, 0);
//msgrcv(msgid2, &message2, sizeof(message2), 1, 0);
}
EDIT : I have removed the error checking on function calls here for simplicity. There are no errors in this case.
c
linux
ipc
message-queue
interprocess
0 Answers
Your Answer