Skip to content

Inter Process Communication (IPC)

benliao1 edited this page Aug 19, 2020 · 9 revisions

Programs running on a machine must be able to communicate with each other for any large and useful program. Since UNIX compartmentalizes each running program into its own process, all communication between processes (aptly called Interprocess Communication, or IPC) must go through the operating system. The operating system provides several methods of IPC, all offering their own advantages and disadvantages. A major design decision in any major software project is which type of interprocess communication to use.

The pages in this section go into several major types of interprocess communication, all of which are used somewhere in Runtime. To not repeat content, a summary will not be written here; please read the actual pages for an in-depth look at what each IPC method is and how to use it.

However, we will provide a chart here illustrating some of the key differences between the various IPC methods:

Bidirectional Processes Must Have Parent-Child Relationship Can Have Multiple Readers/Writers
Pipes No Yes No
FIFO No No Yes
Serial Yes No No
Shared Memory Yes No Yes
Signals No Yes N/A
Sockets (TCP) Yes No No
Sockets (UDP) Yes No Yes
Sockets (Unix; Streams) Yes No No
Sockets (Unix; Datagrams) Yes No Yes

(continued)

Reliable Connection-Oriented Use Over Network Use Over USB Use Within Same Machine Has Name on File System
Pipes Yes Yes No No Yes No
FIFOs Yes No No No Yes Yes
Serial No No No Yes No Yes
Shared Memory N/A N/A No No Yes Yes (on Linux)
Signals Yes N/A No No Yes No
Sockets (TCP) Yes Yes Yes No Yes (using 127.0.0.1) No
Sockets (UDP) No No Yes No Yes (using 127.0.0.1) No
Sockets (Unix; Streams) Yes Yes No No Yes Yes
Sockets (Unix; Datagrams) Yes No No No Yes Yes

Lastly, we will give a brief summary of common use cases for the various forms of IPC:

  • On Different Machines: These IPC methods are used for communication between different machines.
    • Serial Communication: This is used between processes on different devices that are connected by wire (usually USB, but also other kinds of serial cables).
    • Networking: This is used when your processes are running on separate machines and connected over the network
      • TCP optimizes for reliability
      • UDP optimizes for speed (but still slow compared to communication on the same machine; may drop or duplicate datagrams)
  • Within Same Machine: These IPC methods are used for communication between processes on the same machine.
    • Signals: These are used for processes to notify other processes that certain events have happened. They are not used for transferring any data.
    • Pipes: This is used for one process to dump a bunch of data somewhere for another process on the same machine to pick up and perform some computations on. However, pipes are one of the slowest form of IPC available between two processes on the same machine.
    • FIFOs: These have similar uses to normal pipes, but are slightly faster and more general, since they can handle more than one process dumping data and more than one process picking the data up to run some computation on them.
    • Unix Domain sockets: These have similar use cases to pipes and FIFOs, but support two-way communication. Depending on the implementation, Unix Domain sockets can be slightly slower or slightly faster than both pipes and FIFOs.
    • Shared Memory: These are the fastest kind of IPC available on modern Unix systems. They are more "high-maintenance" then the other forms of IPC, and are usually used for transferring large amounts of very structured data (data that always has the same form and doesn't have, for example, variable-length components like strings).