Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


Admittedly, it is difficult to digest the amount of information in this structure. However, the structure
contents can be broken down into sections, each of which represents a specific aspect of the process:

❑ State and execution information such as pending signals, binary format used (and any emulation
information for binary formats of other systems),process identification number (pid), pointers to
parents and other related processes, priorities, and time information on program execution (e.g.,
CPU time).
❑ Information on allocated virtual memory.
❑ Process credentials such as user and group ID, capabilities,^2 and so on. System calls can be used
to query (or modify) these data; I deal with these in greater detail when describing the specific
subsystems.
❑ Files used: Not only the binary file with the program code but also filesystem information on all
files handled by the process must be saved.
❑ Thread information, which records the CPU-specific runtime data of the process (the remaining
fields in the structure are not dependent on the hardware used).
❑ Information on interprocess communication required when working with other applications.
❑ Signal handlers used by the process to respond to incoming signals.

Many members of the task structure are not simple variables but pointers to other data structures
examined and discussed in the following chapters. In the present chapter, I consider some elements
oftask_structthat are of particular significance in process management implementation.

statespecifies the current state of a process and accepts the following values (these are pre-processor
constants defined in<sched.h>):

❑ TASK_RUNNINGmeans that a task is in a runnable state. It does not mean that a CPU is actually
allocated. The task can wait until it is selected by the scheduler. This state guarantees that the
process really is ready to run and is not waiting for an external event.
❑ TASK_INTERRUPTIBLEis set for a sleeping process that is waiting for some event or other. When
the kernel signals to the process that the event has occurred, it is placed in theTASK_RUNNING
state and may resume execution as soon as it is selected by the scheduler.
❑ TASK_UNINTERRUPTIBLEis used for sleeping processes disabled on the instructions of the kernel.
Theymaynotbewokenbyexternalsignals,onlybythekernelitself.
❑ TASK_STOPPEDindicates that the process was stopped on purpose — by a debugger, for example.
❑ TASK_TRACEDis not a process state per se — it is used to distinguish stopped tasks that are cur-
rently being traced (using theptracemechanism) from regular stopped tasks.

The following constants can be used both in the task state field ofstruct task_struct, but also in the
fieldexit_state, which is specifically for exiting processes.

❑ EXIT_ZOMBIEis the zombie state described above.
❑ EXIT_DEADis the state after an appropriatewaitsystem call has been issued and before the task
is completely removed from the system. This state is only of importance if multiple threads issue
waitcalls for the same task.

(^2) Capabilities are special permissions that can be granted to a process. They allow the process to perform certain operations that nor-
mally may be performed only by root processes.

Free download pdf