In: Computer Science
What are the pros and cons of data exchange using pipes/sockets vs data exchange using shared memory.
Inter-Process communication can take place via pipes, sockets or shared memory.
A pipe is a unidirectional communication mechanism that permits serial transfer of bytes from the writing process to the reading process. Typically, a pipe is used for communication between two threads of a process or between a parent and child process.
A socket is a bidirectional communication mechanism that can be used to communicate with another process on the same machine or on a different machine.
Shared memory allows two or more processes to access the same memory region, which is mapped onto the address space of all participating processes.
Pros and cons are listed below:
Pipes, Sockets
Simple and controlled. Can be extended to network sockets as necessary with little or no modification. Programming model requires serialization, which in turn requires you to think about what data actually gets transferred from A to B. Synchronization is necessarily built-in to the communication mechanism; no other synchronization necessary.
Shared Memory
Does not necessarily require a syscall (therefore potentially faster). Sharing does not explicitly require data to be transferred -- data can be made available that the recipient does not retrieve (bandwidth does not have to be wasted transferring data that the recipient won't use). No serialization/deserialization step means no time spent on communication overhead.