The so-called process is an instance of the execution of a program. It is an important abstraction in the modern operating system, and we analyze the process management implementation on Linux from the lifecycle of the process: creation, execution, and extinction.
One: Preface
Process management structure;
In the kernel, each process corresponds to a task. That's what we used to say about PCB. Its structure is as follows (Include/linux/sched.h):
struct Task_struct {
volatile long state; /*-1 unrunnable, 0 runnable, >0 stopped
/void *stack;
atomic_t usage;
unsigned int flags; /* per process flags, defined below * *
unsigned int ptrace;
int lock_depth; /* BKL Lock depth * ...
...
}
Since this structure contains all the information about the process, it is very large and we will analyze the meaning of each member in future analysis.
Storage of Task_struct:
Process switching is very frequent during the system operation, so we need a way to quickly get the task_struct of the current process. The Linux task_struct is stored as shown in the following illustration: