Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


Most of the code to generate the information is already present in kernel 2.6.24, but the final connection
with/procwill only be made in the following kernel release.

2.3.1 Process Types


A classicalUnixprocess is an application that consists of binary code, a chronological thread (the com-
puter follows a single path through the code, no other paths run at the same time), and a set of resources
allocated to the application — for example, memory, files, and so on. New processes are generated using
theforkandexecsystem calls:

❑ forkgenerates an identical copy of the current process; this copy is known as achild process.All
resources of the original process are copied in a suitable way so that after the system call there
are two independent instances of the original process. These instances are not linked in any way
but have, for example, the same set of open files, the same working directory, the same data in
memory (each with its own copy of the data), and so on.^3
❑ execreplaces a running process with another application loaded from an executable binary file.
In other words, a new program is loaded. Becauseexecdoes not create a new process, an old
program must first be duplicated usingfork,andthenexecmust be called to generate an addi-
tional application on the system.

Linux also provides theclonesystem call in addition to the two calls above that are available in allUnix
flavors and date back to very early days. In principle,cloneworks in the same way asfork,butthenew
process is not independent of its parent process and can share some resources with it. It is possible to
specifywhichresources are to be shared and which are to be copied — for example, data in memory,
open files, or the installed signal handlers of the parent process.

cloneis used to implementthreads. However, the system call alone is not enough to do this. Libraries are
also needed in userspace to complete implementation. Examples of such libraries areLinuxthreadsand
Next Generation Posix Threads.

2.3.2 Namespaces


Namespaces provide a lightweight form of virtualization by allowing us to view the global properties of
a running system under different aspects. The mechanism is similar tozonesin Solaris or thejailmech-
anism in FreeBSD. After a general overview of the concept, I discuss the infrastructure provided by the
namespace framework.

Concept


Traditionally, many resources are managed globally in Linux as well as otherUnixderivatives. For
instance, all processes in the system are conventionally identified by their PID, which implies that a
global list of PIDs must be managed by the kernel. Likewise, the information about the system returned
by theunamesystem call (which includes the system name and some information about the kernel) is the
same for all callers. User IDs are managed in a similar fashion: Each user is identified by a UID number
that is globally unique.

(^3) In Section 2.4.1, you will see that Linux does use the copy-on-write mechanism to not copy memory pages of the forked process
until the new process performs a write access to the pages — this is more efficient than blindly copying all memory pages immedi-
ately on execution offork. The link between the memory pages of the parent and child process needed to do this is visible to the
kernel only and is transparent to the applications.

Free download pdf