Inter-process Communication

The operating system provides various methods for processes to communicate with each other, called IPC (inter-process communication). One obvious mechanism is through the file system – by writing and reading from the same files, processes can share data. Others include signals, semaphores, shared memory mapping, sockets, pipes, and so on.

We will discuss these mechanisms in more detail later in the course, but for now you should understand a few basic types of IPC: Signals, Pipes, and Sockets.

Signals

A process with appropriate privileges can request to send a signal to another process; the kernel will handle the delivery of that signal next time the target process returns from kernel mode, which typically happens so often that signals usually appear to arrive almost instantaneously. If a process is sleeping, the kernel will also “kick” a signaled process and add it to the scheduler queue so that it can be woken up and respond to the signal. Sometimes the kernel also generates signals directly, such as SIGSEGV, when a process does something it’s not supposed to.

Each type of signal has a different meaning and default behavior associated with it. A process can also register its own custom signal handlers for most signals in order to override the default behavior; SIGKILL and SIGSTOP are the two exceptions to this rule. Below is a list of some commonly encountered signals, along with their default behaviors.

Signal Name

Default Action

Description

SIGABRT

Core dump [1]

Abort signal

SIGALRM

Terminate

Timer signal

SIGCHLD

Ignore

Child stopped or terminated

SIGCONT

Continue

Continue (if stopped)

SIGFPE

Core dump

Floating-point exception

SIGHUP

Terminate

Hangup detected on controlling terminal or death of controlling process

SIGINT

Terminate

Interrupt from keyboard

SIGKILL

Terminate

Kill signal

SIGPIPE

Terminate

Broken pipe: write to pipe with no readers

SIGQUIT

Core dump

Quit from keyboard

SIGSEGV

Core dump

Invalid memory reference

SIGSTOP

Stop

Stop process

SIGTSTP

Stop

Stop typed at terminal

SIGTERM

Terminate

Termination signal

SIGTRAP

Core dump

Trace/breakpoint trap

SIGTTIN

Stop

Terminal input for background process

SIGTTOU

Stop

Terminal output for background process

SIGUSR1

Terminate

User-defined signal 1

SIGUSR2

Terminate

User-defined signal 2

Pipes

Processes can also open a special type of a file called a pipe; pipes are anonymous (i.e. they don’t exist as named files in the file system), and they are managed by the kernel as a simple FIFO (first-in, first-out) data buffer. Each pipe has a read and a write end, allowing one-way communication between two processes. Since pipes don’t exist in the file system, the two ends of a pipe become distributed to separate processes by inheriting the ends of a pipe that was created by a shared ancestor.

A pipe usually has just one writer and one reader, but there is no restriction on the number of readers or writers that have it open at a time. There is still only one copy of data in the pipe, so multiple readers and writers may interfere with each other unless designed to operate cooperatively. This type of arrangement is often used to implement parallel processing, such as job queues – multiple writers can add job descriptions to a queue, and multiple readers can consume whatever jobs are available.

Unix Sockets

Sockets are similar to pipes, except that they are associated with a named resource so that unrelated processes can access them. There are different types of sockets, which includes familiar socket types such as TCP/IP and UDP/IP sockets which operate over a network and are bound to URLs. Unix also provides a type of socket called a Unix Domain Socket, which is bound to a path in the file system; these are also called fifos or named pipes, and are typically used by system services running in the background to provide an access point for users to interact with and request service.