0. Summary of the analysis of Linux system processes
This article includes a brief description of Linux, process, process status, process scheduling and personal understanding.
1.Linux
What is 1.1Linux?
Linux is a free-to-use and free-to-propagate Unix-like operating system, a POSIX and Unix-based multiuser, multitasking, multi-threaded and multi-CPU operating system. It can run major UNIX tools software, applications, and network protocols. It supports 32-bit and 64-bit hardware. Linux inherits the design idea of Unix as the core of network, and is a stable multi-user network operating system.
2. Process2.1 What is a process
Process: The basic unit that can run independently and be allocated as a resource in a system, which consists of a set of machine instructions, data and stacks, and is an active entity that can run independently.
-
- A process is a single execution of a program
- Processes can be executed in parallel with other computations
- A process is the process by which a program runs on a data set, which is an independent unit of system resource allocation and scheduling.
2.2 Characteristics of the process
- Dynamic: The essence of the process is the process of execution of a program, the process is dynamic generation, the dynamic extinction.
- Concurrency: Any process can execute concurrently with other processes.
- Independence: A process is a basic unit that can run independently, and is also an independent unit for allocating resources and dispatching the system.
- Asynchrony: Because of the inter-process constraints, the process has a discontinuity of execution, that is, the process at its own independent, unpredictable speed forward.
2.3 Organization of the process
Task_struct is a data structure of the Linux kernel that is loaded into RAM and contains information about the process. Each process puts its information in the TASK_STRUCT data structure, Task_struct contains the following:
- identifier: A unique identifier that describes this process, used to differentiate other processes.
- Status: Task status, exit code, exit signal, etc.
- priority: Priority relative to other processes.
- Program counter: The address of the next instruction that will be executed in the program 。
- Memory pointers: includes pointers to program code and process-related data, There are also pointers to memory blocks that are shared with other processes.
- Context data: Data in the processor's registers when the process executes 。
- I/O status information: Includes displayed I/O requests, The I/O device that is assigned to the process and the list of files used by the process.
- accounting information: can include the sum of processor time, Total number of clocks used, time limit, bookkeeping number, etc.
The data structure that holds the process information is called task_struct and can be found in the include/linux/sched.h. So the processes running in the system are in the kernel in the form of task_struct lists.
In order to manage the process of creation, extinction (handling of the zombie process and other operations) using the father-son, sibling relationship;
In order to handle the same semaphore uniformly, the thread group relationship is used, and the hash table relationship is used for the convenience of global lookups;
In order to dispatch the program, the run queue, wait queue data structure is used.
2.4 Classification of the process
Linux separates processes into real-time and non-real-time processes (normal processes), where non-real-time processes are further divided into interactive processes and batch processes.
|
description |
instance |
interactive processes (interactive process) |
The process must be awakened soon, Otherwise the user will feel the system unresponsive |
shell, text-editing programs and graphics applications |
batch process |
|
programming language Compiler program , database search engine, and scientific computing |
Real-time processes (real-time process) |
These processes are required by a strong scheduling process that is never blocked by a low-priority process. And their response time is as short as possible. |
Video audio applications, robot control programs, and procedures for collecting data from physical sensors |
2.5 Process Identifiers
Knowing that the process has been produced, it is natural to think of how the system is running at the same time and how the operating system can effectively manage so many processes.
For effective management in Linux, a TASK_STRUCT data structure is used to describe a process in a complete way.
The description of the process in Linux up to 300 lines of code, defining a very member, can be broadly divided into the following sections:
-Process status (state)
-Process scheduling information (scheduling information)
-Various identifiers (Identifiers)
-Process Communication related information (IPC)
-Time and timer information (times and timers)
-Process link information (links)
-FileSystem information (file system)
-Virtual Memory information
-page Management Information (pages)
-Symmetric Multi-processor (SMP) information
-processor-related environment (context) information (Processor specific context)
-Other information
3. Status of the process
3.1 Process Status
volatile Long State ; int exit_state;
View Code
3.2 possible values for a State Member
#define task_running 0 #define Task_i Nterruptible 1 #define task_uninterruptible 2 #def INE __task_stopped 4 #define __task_traced 8 /* in tsk->exit_state */ #define exit_zombie #define EXIT _dead /* in Tsk->state again */ #define task_dead #define task_wakekill #define task_waking
View Code
3.3 Each state of a process
Task_running |
Indicates that the process is executing or is in the state of readiness to execute |
Task_interruptible |
The process will transition from the state to the ready state as soon as the waiting condition is set, because it waits for some condition to be blocked (pending) |
Task_uninterruptible |
The meaning is similar to task_interruptible, but we can't wake them up by transmitting arbitrary signals, but only when the resources it waits for are available. |
task_stopped |
Process is stopped execution |
task_traced |
Processes are monitored by processes such as debugger. |
Exit_zombie |
The execution of the process is terminated, but its parent process has not yet used a system called wait () to know its termination information, when the process becomes a zombie process |
Exit_dead |
Process is killed, that is, the final state of the process. |
Task_killable |
When the process is in this new sleep state that can be terminated, it works like task_uninterruptible, but can respond to a deadly signal |
3.4 state transition Diagram
4. Scheduling of Processes4.1 What is process scheduling?
The scheduler uses some information to determine which process in the system should run most, and to combine the status information of the process to ensure the system is fair and efficient.
This section of information typically includes the category of the process (normal or real-time), the priority of the process, and so on.
In layman's terms, the process scheduling is the use of certain information and according to a kind of rules to determine the process of rational operation, it is obvious to be reasonable and efficient to organize the process to run, this rule is crucial.
This rule is what we call the scheduling algorithm. We will explain the scheduling algorithm in detail later.
It should be emphasized that the scheduler always chooses the vruntime running the slowest process to execute.
This is called "complete fairness". In order to differentiate between different priority processes, the high-priority process vruntime grows so slowly that it may get more running opportunities.
Design Thinking of 4.2 cfs
Ideas we can simply understand to allocate run time based on the weight of the process, the time allocated to the process is calculated according to the formula:
Elapsed time assigned to the process = Schedule period * The sum of process weights/all process weights.
4.3 data structure of CFS
5. View of the operating system process model
After continuous improvement, the Linux scheduling algorithm transforms from an O (1) Scheduler of the previous 2.6 kernel to a red-black tree as the basic data structure algorithm . Provides a good experience for users. With the gradual improvement of the algorithm, the space of the algorithm optimization is getting smaller, but I believe that after the study of the operating system, we will be able to find the improved breakthrough point, or develop a better algorithm.
6. Links to Related Materials
9281081
43339007
Http://blog.sina.com.cn/s/blog_79e165ef0102wcvz.html
7894211
First assignment: Analysis of the Linux process