A two-way communication using message queue in C can be implemented as follows:
int mq_sender_to_receiver = mq_open("/sender_to_receiver", O_CREAT | O_RDWR, 0666, NULL);
int mq_receiver_to_sender = mq_open("/receiver_to_sender", O_CREAT | O_RDWR, 0666, NULL);
pid_t pid = fork();
mq_send()
to send a message to the Receiver.char msg[100] = "Hello, Receiver!";
mq_send(mq_sender_to_receiver, msg, 100, 0);
mq_receive()
to receive the message from the Sender.char msg[100];
mq_receive(mq_sender_to_receiver, msg, 100, NULL);
mq_send()
to send a message to the Sender.char response[100] = "Hello, Sender!";
mq_send(mq_receiver_to_sender, response, 100, 0);
mq_receive()
to receive the message from the Receiver.char response[100];
mq_receive(mq_receiver_to_sender, response, 100, NULL);
if (pid == 0) {
// Sender process
printf("Sender received: %s\n", response);
} else {
// Receiver process
printf("Receiver received: %s\n", msg);
}
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-10-30 11:00:00 +0000
Seen: 21 times
Last updated: Feb 02 '22
How can TMC2209 be connected to Arduino for communication?
What is the process for altering svn branches with git-svn?
What is the process to italicize certain keywords in visual studio code?
What is the process for developing a JTable that has both row and column headers?
What is the process for removing a dat.GUI element?
How to solve the issue "process is running" in Visual Studio Debugging?
What is the process of moving information from one tab to another in Excel by transposing it?
What is the process of dividing the WSD dataset (in CSV format) into tokens called?
What is the process of uploading a file using NextJS and formidable?