Skip to content
UoL CS Notes

Inter-process Communication

COMP124 Lectures

Process interaction

Processes that do not need to interact with any other processes are known as independent processes.

In modern systems, many processes will work together. These are known as cooperating processes.

The operating system provides synchronisation and communication mechanisms for cooperating processes.

Synchronisation & Communication

Synchronisation

If a process can only do its work when another process has reached a certain point, we need a way of informing it such as:

  • Semaphores and signals.

    Communication

    One process passes data directly to another process. In Unix this can be done with:

  • Pipes and sockets.

Unix Signals

A process can usually be terminated by typing CTRL-C:

  • Actually sends a signal to process.
  • Process responds by aborting.

Signals can be sent from one process to another:

  • signal() system call.

Signals can be sent from the command line using kill command:

 $ kill -<signal> <pid>

kill -9 12345 sends signal 9 (kill signal) to process 12345

Responding to Signals

A receiving process can respond to a signal in three ways:

  • Perform default action (e.g. abort).
  • Ignore the signal.
  • Catch the signal:
    • Execute a designated procedure.

The ‘kill’ signal (signal 9) cannot be caught or ignored.

  • Guaranteed way to stop process

Example Kill Signals

Number Name Action
1 HUP Hang up
2 INT Interrupt
3 QUIT Quit
6 ABRT Abort
9 KILL Non-catch-able, non-ignorable kill
14 ALRM Alarm clock
15 TERM Software termination signal

Pipes

The UNIX command wc –l <file> counts the number of lines in file.

If we just type wc –l we don’t get an error. Instead, data is read from standard input (keyboard by default).

  • Similarly for output files and standard output (screen).

The pipe symbol | attaches the standard output of one program to the standard input of another:

 $ who | wc -l

Common wc flags

Flag Action
-l Number of lines
-w Number of words
-c Number of characters

By default, all three stats are displayed. Flags state what stats appear.

Sockets

A socket is a communication endpoint of a channel between two processes:

  • Unlike pipes, communication is bi-directional.
  • Unlike pipes, the processes:
    • Do not need to have the same lineage.
    • Do not need to be on the same machine.
    • Do not even need to be on the same local-area network.

When two processes communicate using sockets, one is designated the server and the other the client:

  • In some cases, doesn’t matter which is which.

More usually, a daemon server process offers a service to many clients.

Usually pipes and sockets are implemented as files in a special part of the file system.