Message queue and shared memory both are used to achieve interprocess communication(IPC). Use of message queue and shared memory both have there own advantages as well as disadvantages.
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
ย
Message queue and shared memory
1. Narayan Lal Menariya August 30,2018
Message queue and shared memory
Messagequeueand shared memory both areused to achieve interprocess
communication(IPC). Useof messagequeueand shared memory both havethere own
advantages as well as disadvantages. Let first havea brief description about message
queue and shared memory later i will sharemy own written codewith you.
1. Message Queue:By default messagequeueallows FIFO order of accessing
data/messages from messagequeue. But process can read any messageby
defining message_type whilecalling msgrcv() system call.
a. Messagequeueis kernel persistence: It means messagequeuewill remain
aliveunless and until you will not deleteit explicitly or will not shutdown the
system and restart it back.
b. messagequeues are stored in kernel space.
c. messagequeueis not broad casting.
d. system call overheads aremorein messagequeue.
2. Shared Memory: Shared memory get placein heap memory(user space) thus
system call overheads arevery less.
a. Destructivereading is not therein shared memory but it is present in caseof
messagequeue.
b. Shared memory is faster than messagequeue.
c. Shared memory is broad casting so semaphoresareused for synchronization.
Code for Message queue: In this codeoneprocess writes completestructurein message
queue whileother process read that structure. A student structureis created which
receives student Id and Student Namefrom user and writes into messagequeueon
desired message_type. message_type should beinteger value. At thereceiver end side
user need to input message_type, onceuser will enter it data present on this location
will be fetched and will present in front of you.
This code is completely error freeand implemented by meown. I have not copied it
from anywhere.
Program to writein messagequeue: WriteIn_messageQueue.c
1. /*
2.
3. NarayanLal Menariya:August28,2018
4.
5. * */
6.
7. #include<sys/types.h>
8. #include<sys/ipc.h>
9. #include<sys/msg.h>
10. #include<string.h>