Interprocess Communication (IPC).
In this chapter, we examine classical IPC: pipes, FIFOs, message queues, semaphores, and shared memory.

1 Pipes

Pipes are the oldest form of UNIX System IPC and are provided by all UNIX systems. Pipes have two limitations:

  1. Historically, they have been half duplex[半双工] (i.e., data flows in only one direction).
  2. Pipes can be used only between processes that have a common ancestor.

2 FIFOs

FIFOs are sometimes called named pipes. Unnamed pipes can be used only between related processes when a common ancestor has created the pipe. With FIFOs, however, unrelated processes can exchange data.

3 Message Queues

A message queue is a linked list of messages stored within the kernel and identified by a message queue identifier.

4 Semaphores

A semaphore isn’t a form of IPC similar to the others that we’ve described (pipes, FIFOs, and message queues). A semaphore is a counter used to provide access to a shared data object for multiple processes.

5 Shared Memory

Shared memory allows two or more processes to share the same pages of memory. No kernel intervention is required to exchange data via shared memory. Once a process has copied data into a shared memory segment, that data is immediately visible to other processes. Shared memory provides fast IPC, although this speed advantage is somewhat offset by the fact that normally we must use some type of synchronization technique, such as a System V semaphore, to synchronize access to the shared memory.

A POSIX shared memory object is used to share a region of memory between unrelated processes without creating an underlying disk file.