Program for Inter Process Communication using Message Queues || msgget || msgsnd || msgrcv || IPC

preview_player
Показать описание
In this lecture on Program for Inter Process Communication using Message Queues, you will learn how processes can communicate using message queues in Linux using C programming. Message queues are almost similar to named pipes with the exception that they do not require the opening and closing of pipes. But, they face one similar problem like named pipes; blocking on full pipes. Message queues send blocks of data from one process to another.
There are 4 important functions that we will use in the programs to achieve IPC using message queues

int msgget(key_t key, int msgflg);
int msgsnd(int msqid, const void *msg_ptr, size_t msg_sz, int msgflg);
int msgrcv(int msqid, void *msg_ptr, size_t msg_sz, long int msgtype, int msgflg);
int msgctl(int msqid, int command, struct msqid_ds *buf);



Reference Videos for Inter Process Communication:

Tools Required:
1. Linux environment
2. Basic knowledge of C Language
3. gcc compiler installed

Reference Links:

Other Playlists:

Was this tutorial about Program for IPC using message queues helpful? If so, please share. Let me know your thoughts in the comments.

#linux #oslab #os #dextutor #ipc
Рекомендации по теме
Комментарии
Автор

Thanks a lot sir for helping.
Your Teaching is superb.

nithishjh
Автор

This video is very nice, it help me to understand message queue!

zhoualias
Автор

HI! Can you please tell me why do I need to create a structure to send the message when I am using message queues? I mean, there is no such requirement while sending messages using shared memory, then why do I require it here? Would be grateful if you reply :)

girikgarg
Автор

hello sir, i tried executing this program in ubuntu app on my windows OS, it did not create any message queue, what could be the reason?

madhurikabudaraju
Автор

Hey great content,
But please update your site
I do not feel safe in going to your site through my office laptop

nikhilkumar_
Автор

Just my 1 rupee opinion/comment & please take it FWIW.

This is a good introductory program for new learners.

In an real world programming scenario, like in a good software development company - in the mq_send.c file being shown in this youtube video, we should set the integer variable "running" to 0 if the msgget() system call fails. This will ensure that the program prints the error message related to Message Queue creation failure and does not even enter the "while(running)" loop. Otherwise the program will enter the while loop and all the messages obtained from the user input will never ever get sent to the receiver program.

I do see that there is an exit(0) line when Message Queue creation is a failure in the mq_send.c source code file in your indicated website. Here too, the usage of "exit(0)" indicates a success in the execution of the program. But for this failure scenario we can use either a non-zero positive integer or a simpler "exit(EXIT_FAILURE)" to indicate the program suffered a failure.

One more missing item is the return value for the main() function in mq_send.c file.This program should return an integer (indicating a success or failure) when it exits from the while() loop.

woodseller
Автор

Sir, I don't know why but I'm unable to get the output for the second (recieve) program . I'm doing it on ubuntu in my windows os

rrohith
Автор

I am unable to send void* type data inside a structure and getting output as segmentation fault

srikanthreddy
Автор

sir, fgets means is it storing in a file?

samadeekshareddy
join shbcf.ru