I. Concept of the process
A process is an instance of program execution. The operating system allocates system resources in process units, and processes are the smallest units of resource allocation.
Four elements of the Linux process
1: A program that is executed by a process that can be executed by multiple processes.2: Stand-alone kernel stack.3: Process Control Fast (task_struct: With this data structure, the process can become a basic unit of kernel scheduling to accept the kernel scheduling. At the same time, the structure also records the resources occupied by the process.4: Separate storage space: that is, with proprietary user space, in addition to the previous kernel space and user space.
Second, Process descriptor
1. The process descriptor contains all the information related to a process.
struct task_struct{
Process information
}
2. Process Descriptor Processing
For each process, the kernel allocates a separate memory area for it, which stores the kernel stack and a small process descriptor--thread_info structure corresponding to that process.
struct Thread_info {
}
Iii. Status of the process
Available for operation (task_running)
interruptible Wait (task_interruptble)
Non-disruptive Wait (task_uninterruptilbe)
Pause (task_stopped)
Tracking (task_traced)
Zombie (Task_zombie)
Zombie Undo (Exit_dead)
Thread
A thread exists in a process and is the smallest unit of operating system scheduling execution. In the popular point, the thread is the work.
Iv. Inter-process relations
Process 0 and Process 1 are created by the kernel, and Process 1 (init) is the ancestor of all other processes.
V. Process and wait queue
Wait queues (wait queue) are used to enable a process band to wait for a particular event to occur without frequent polling, the process sleeps within the wait time, and the kernel automatically wakes up when the waiting event occurs
1. Waiting for queue-related data structures
Each wait queue consists of two parts: the wait queue header (struct wait_queue_head_t) and the wait queue member (struct wait_queue).
- struct __wait_queue_head {
- spinlock_t lock; /* because the wait queue can be modified at any time when the interrupt is interrupted, set a spin lock to ensure consistency */
- struct list_ head task_list;
- };
- typedef struct __wait_ queue_head wait_queue_head_t;
-
- struct __wait_ queue {
- unsigned int flags; /* indicates whether the waiting process is a mutex or a non-mutex process */
- struct task_ struct *task; /* task_struct*/
- wait_queue_func_t func;
- struct list_ head task_list;
- };
- typedef struct __wait_ queue_head wait_queue_head_t
2. The use of the wait queue is divided into the following two parts: (1) to make the current process sleep in a waiting queue, call wait_event (or an equivalent function), after which the process goes to sleep and gives control to the scheduler. In the case of block devices, when the kernel makes a request to a block device, because the data transfer does not occur immediately, the process sleep (2) corresponds to a process where the WAKE_UP function (or an equivalent function) must be called to wake the waiting queue for sleep.
V. Process creation
Fork Vfork
(iii) process