I was reading a tutorial about shared memory and found the following statement: "If a process wishes to notify another process that new data has been inserted to the shared memory, it will have to use signals, message queues, pipes, sockets, or other types of IPC.". So what is the main advantage of using shared memory and other type of IPC for notifying only instead of using an IPC that doesn't need any other IPC type to be used, like message queue and socket for example?
Inter Process Communication through shared memory is a concept where two or more process can access the common memory. And communication is done via this shared memory where changes made by one process can be viewed by another process.
IPC is the way by which multiple processes or threads communicate among each other. IPC in OS obtains modularity, computational speedup and data sharing. Different ways of IPC are pipe, message passing, message queue, shared memory, direct communication, indirect communication and FIFO.
The IPC shared semaphore facility provides process synchronization. Shared memory is the fastest form of interprocess communication. The main advantage of shared memory is that the copying of message data is eliminated.
Message passing is a time consuming process because it is implemented through kernel (system calls). In shared memory make sure that the processes are not writing to the same location simultaneously. Message passing is useful for sharing small amounts of data so that conflicts need not occur.
Synchronization in Interprocess Communication The two types of semaphores are binary semaphores and counting semaphores.
Two main methods for inter-process communication are shared memory and message passing. In the shared memory method, two processes communicate with each other using common shared memory. shmget(), shmat(), shmdt(), shmctl() are the commonly used system calls in the shared memory method.
The distinction here is IPC mechanisms for signalling versus shared state.
Signalling (signals, message queues, pipes, etc.) is appropriate for information that tends to be short, timely and directed. Events over these mechanisms tend to wake up or interrupt another program. The analogy would be, "what would one program SMS to another?"
Shared memory, compared with the above, is more effective for sharing relatively large, stable objects that change in small parts or are read repeatedly. Programs might consult shared memory from time to time or after receiving some other signal. Consider, what would a family of programs write on a (large) whiteboard in their home's kitchen?
With these examples, you might say that shared memory is closer to a file than to an IPC mechanism in the strictest sense, with the obvious exceptions that shared memory is
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With