This chapter mainly analyzes the concepts of process definition, state, data structure in the view of code.
Definition of the process
A process is a running program that is a dynamic executable entity. While a program is a collection of code and data, the code is a static entity that can be used by multiple processes, such as the same application that can run on different computers to produce multiple processes.
Process four elements
The four elements of a process are mainly for the differences between threads and processes in code:
l have a procedure for its execution
l have process-specific kernel stack space
l have a kernel control block (with a task_struct data structure) with kernel control blocks to be dispatched by the kernel
l have a separate user space
How processes, user threads, kernel threads:
Status of the process
1) #defineTASK_RUNNING 0
is being executed by the CPU, or is ready to be executed at any time. The process has just been created in this state.
2) #defineTASK_INTERRUPTIBLE 1
The waiting process is awakened when the waiting condition is true, or it can be awakened by a signal that is interrupted.
3) #defineTASK_UNINTERRUPTIBLE 2
A waiting process that wakes up when the resource is valid, but cannot be awakened by a signal or interrupt from another process.
4) #define__TASK_STOPPED 4
the process aborted execution. When the sigstop or SIGTSTP signal is received into this state, the process returns to the Task_running state after the Sigcont signal is received.
5) #define__TASK_TRACED 8
processes in the debug state
6) #defineEXIT_ZOMBIE 16
Indicates that the process has terminated execution, but the parent process has not collected information about the process's death through Waitpid ().
7) #defineEXIT_DEAD 32
The final state of the process termination, the parent process has collected information about the process death, and the process will be deleted by the system.
8) #defineTASK_DEAD 64
Process exits are in this state (Exit_dead and Exit_zombie are recorded by a separate variable, which is a subdivision of the Task_dead).
9) #defineTASK_WAKEKILL 128
Similar to the new state of the Task_uninterruptible,linux 2.6.25 kernel, it can be awakened by a fatal signal (SIGKILL).
#define Task_killable (Task_wakekill | task_uninterruptible)
#define TASK_STOPPED (Task_wakekill | __task_stopped)
#define TASK_TRACED (Task_wakekill | __task_traced)
#define TASK_NORMAL (task_interruptible | task_uninterruptible)
Data structure of the process
In Linux, processes and threads are described using the TASK_STRUCT data structure, and the following will tell the purpose of the major data structure members.
volatile long state; Process status
unsigned int flags; Process description Related Flags
int Prio, Static_prio, Normal_prio; Process priority, the higher the value, the smaller the priority
unsigned int rt_priority; Process-run priority
unsigned int policy; Process scheduling Policy
int exit_state; Status when the process exits
struct Mm_struct *mm; Process Memory Management Information
pid_t pid;//Process Number
Data structure and kernel stack space
Linux has a kernel stack of only two page sizes (8K), and in the 2.4 kernel, task_struct is placed at the bottom of the kernel stack.
However, in the 2.6 version of the data structure is adjusted to occupy the storage space, the kernel stack at the bottom of the only one thread_info_structure, this structure describes the location of Task_struct.
The Linux kernel has a current pointer that always points to the task_struct being executed.
Linux kernel development-Process Control