Interprocess Communication (IPC)

IPC is an operating system facility that allows processes within a system or from different system to communicate (exchange information and synchronise) with each other. It is important since it allows information sharing between processes, Parallelism#, modularity, and convenience.

There are several methods of IPC:

For the latter three methods (message queues, semaphore and shared memory), the kernel will create an object called IPC object which stores its information. The following codes show an example for an IPC object named as ipc_perm:

struct ipc_perm {
  uid_t uid;    // owner's user id
  gid_t gid;    // owner's group id
  uid_t cuid;   // creater's user id
  gid_t cgid;   // creater's group id
  mode_t mode;  // permissions
  ulong_t seq;  // slot usage sequence number
  key_t key;    // IPC key associated with the object
};

Note: See IPC Facilities Key#.

These IPC objects could be checked with the command ipcs {flags} (abbreviated from IPC show) comes with the flags -m (shared memory), -s (semaphore) and -q (message queue), and be removed by ipcrm {obj} {id} (abbreviated from IPC remove) with msg (message queue), sem (semaphore) and shm (shared memory).

Links to this page
  • TTP3121 Chapter 6: Inter Process Communication Part 1
  • Named Pipe (FIFO)

    FIFO is a #Pipe that have names and directory link. This extends its availability to other processes that are not necessarily related to each other to establish an #Interprocess Communication (IPC) channel between them. Although the blocking on read and write when the queue is empty or full is the default, we can specify it to be non-blocking (flag O_NONBLOCK or O_NDELAY) which doesn’t wait for data or processes. Non-blocking read and write in FIFO also allow Concurrent writing. Atomic write is guaranteed up to 4096 bytes.

  • Name Space

    Name Space is a set of possible names for a give type of IPC#. It is especially important for IPC between processes on different systems. The naming conventions for different type of IPC are shown in the following table:

  • IPC Facilities Key

    key_t key is a 32-bit identifier associated with an #Interprocess Communication (IPC) object on a #unix system. It can be obtained from the function ftok() imported from sys/types.h and sys/ipc.h that maps a file’s pathname and an 8-bit integer into a key. The creation of key is shown as below:

#operating-system #networking