Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 5: Locking and Interprocess Communication


file linked with the corresponding instance ofshmid_kernelviashm_fileis created for each shared
memory object. The kernel uses the pointersmh_file->f_mappingto access the address space object
(struct address_space) used to create anonymous mappings as described in Chapter 4. The page tables
of the processes involved are set up so that each process is able to access the areas linked with the region.

5.4 Other IPC Mechanisms


There are other traditional ways of exchanging messages and data between processes in addition to the
IPC mechanisms adopted from System VUnix. Whereas the SysV options are primarily of interest to
application programmers, practically all users who have ever worked with the shell will know signals
and pipes.

5.4.1 Signals


Signals are an older form of communication than the SysV mechanisms. Although they provide fewer
options, they are generally very suited to their purpose. The underlying concept is very simple — the
killcommand sends a signal to a process identified by its PID. The number of the signal is specified
using-s sigand is a positive integer whose maximum size varies depending on processor type. The two
most frequently used variants of the command arekillwithout a signal number, which politely requests
the process to terminate (the process is free to ignore the signal), andkill -9, which is the equivalent of
a signature on an execution warrant (and results in certain death).

In the past, 32-bit systems supported a maximum of 32 signals, but this restriction has now been lifted,
and all signals listed on the kill manual page are now supported. Nevertheless, all the ‘‘classic‘‘ sig-
nals occupy the first 32 positions on the list. They are followed by new signals introduced for real-time
processes.

Processes must install handler routines to process signals. These are invoked when signals are sent to
the processes (but there are several signals such asSIGKILLwhose behavior cannot be overridden). If no
explicit handler routine is installed, the kernel uses a default handler implementation.

Signals introduce several special features that must always be kept in mind. A process can decide toblock
specific signals (sometimes referred to as themaskingof signals). If this happens, the signal is ignored
until the process decides to remove the block. There is therefore no guarantee that a process will be
aware that a signal has been sent to it. When a signal is blocked, the kernel places it on apendinglist. If
the same signal is blocked more than once, only a single occurrence of the signal is placed on the pending
list. No matter how many identical signals are sent, the process receives just one occurrence of the signal
when it removes the block.

TheSIGKILLsignal cannot be blocked and cannot be handled by a process-specific handler function. It
cannot be overridden because it is the last resort to remove an out-of-control process from the system.
This contrasts with theSIGTERMsignal, which can be dealt with by a user-defined signal handler — after
all, the signal is just a polite request to the process to stop work as soon as possible. If a handler is installed
for this signal, the program is, for example, given the opportunity to save data or to ask users whether
they really want to exit the program.SIGKILLdoes not provide such opportunities because the kernel
brings the process to an immediate and abrupt end.

Theinitprocess is granted a special status. The kernel ignores anySIGKILLsignals sent to it. Because
this process is of particular importance to the entire system, it may not be forced to terminate — not even
unintentionally.
Free download pdf