Preface : There are many kinds of operating system now, I mainly talk about Linux operating system, first we understand Linux system, Linux is a set of free-to-use and free-spread UNIX-like operating system, is a POSIX and UNIX-based multi-user , multitasking, multi-threaded, and multi-CPU operating systems. 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. It is primarily used on computers based on the Intel x86 series CPUs. This is the explanation on the Baidu webpage.
How does the 1.Linux system organize the process?
Let's start by knowing what the process is.
1.1-Way (process) is a computer program on a data set on a running activity, the system is the basic unit of resource allocation and scheduling, is the basis of the operating system structure. In the early process design-oriented computer architecture, the process is the basic execution entity of the program, and in the contemporary thread-oriented computer architecture, the process is the container of the thread. A program is a description of instructions, data, and its organization, and the process is the entity of the program. From the explanation on Baidu's homepage.
The 1.2Linux system creation process is created with a fork () system call to create a child process created by the fork () system call, which is called a child process. The function is called once, but returns two times. If the fork () process call succeeds, the difference between two returns is that the return value of the child process is 0, and the return value of the parent process is the process number of the new child process.
The 1,3 Linux Process Control block is a data structure defined by the structure task_struct ,task_struct defined in/include/linux/sched.h, This includes various information needed to manage the process.
task_struct
Structure Description
The owning header file include\linux\sched.h.
Each process is assigned a TASK_STRUCT structure that contains all the information about the process,
The operating system can track information about this structure at any time.
This structure is the most important data structure for the Linux kernel summarization, which we will describe in detail below.
The main information of this structure:
1, process status, will record the process in wait, run, or deadlock
2, scheduling information, by which scheduling function scheduling, how to dispatch, etc.
3. Communication status of the process
4, because to insert the process tree, must have the contact father and son Brother's pointer, of course is task_struct type
5, time information, such as calculate the time to execute, so that the CPU allocation
6, marking, decided to change the process of ownership
7, can read and write open some of the file information
8. Process context and Kernel context
9. Processor context
10. Memory Information
The pieces are all from the relevant links on the information.
1. process status (state)
When the process executes, it changes state depending on the situation. Process state is the basis for scheduling and swapping. The processes in Linux are mainly in the following States
The kernel represents |
Meaning |
Task_running |
Can run |
Task_interruptible |
interruptible Wait Status |
Task_uninterruptible |
Non-interruptible wait state |
Task_zombie |
Dead |
task_stopped |
Time out |
Task_swapping |
Swapping in/swapping out the status of the Linux process |
• Operational status
Processes that are in this state are either running or ready to run. The process that is running is the current process (the process that is pointed to by present), and the ready-to-run process can be run as soon as the CPU is available, and the CPU is the only system resource that these processes wait for. There is a run queue (run_queue) in the system that holds all the processes in a running state, from which a process is selected to run when the scheduler executes. We can see the role of the run queue when we talk about process scheduling later. The current running process is always in that queue, that is, it points to an element in the run queue, only to the point where the scheduler decides.
• Wait Status
A process in that state is waiting for an event or a resource, which must be in a waiting queue (wait_queue) in the system. There are two types of processes that are waiting in Linux: interruptible wait states and non-interruptible wait states. A process that is in an interruptible wait state can be awakened by a signal, and if it receives a signal, the process enters the operational state from the waiting state and joins it to the running queue, waiting to be dispatched, while the process in the non-interruptible wait state waits for a hardware environment that is not satisfied, such as waiting for a specific system resource. It cannot be interrupted under any circumstances, and can only be awakened in a certain way, such as the Wake Function wake_up ().
• Paused status
At this point the process temporarily stops running to accept some special processing. Typically, the process is in this state when it receives a sigstop, SIGTSTP, sigttin, or Sigttou signal. For example, a process that is undergoing debugging is in this state.
• Zombie Status
The process has been terminated, but for some reason the parent process has not yet executed the wait () system call, and the information to terminate the process has not yet been reclaimed. As the name implies, the process in that State is the dead process, which is actually garbage in the system and must be handled accordingly to free up the resources it occupies.
2. How is the process state transformed?
the image source network
3. How is the process scheduled?
In modern operating systems, we are not able to have a process to the corresponding core, which means that this time the management process will need to add a control of its management unit. That is the process scheduler.
The CPU time allocated by the scheduler can not be too long, otherwise it will cause other program response delay, it is difficult to guarantee fairness.
The scheduler does not allocate too much time, and each schedule causes context switching, which is expensive.
Structure of the Scheduler:
Process scheduling is not always possible, as mentioned earlier, the system will have a cycle scheduler, according to the frequency of automatic call Schedule_tick function. Its main function is to trigger the schedule according to the process running time, the call scheduler function which can be displayed when the process encounters the resource waiting to be blocked, and when the kernel space is returned to the user space, it will determine whether the dispatch is currently required, and there is a flag in the THREAD_INFO structure corresponding to the process. The second bit of the Flag field (starting from 0) is used as a rescheduling identity tif_need_resched, which indicates that there is a higher priority process at this time, and the schedule needs to be executed. In addition, the current kernel supports kernel preemption, which can preempt kernel operation at the right time.
4. View of the Linux system process model:
each system has similarities and differences. The core of LINUX is UNIX. UNIX also has many other sub- diffraction operating systems .
The state of the system process constantly switches between various small States, waking up or stopping a state. There is no way to let a process go to a core, so you need a small helper to help manage the process scheduler, to learn more in-depth research.
Reference links
Https://www.cnblogs.com/ck1020/p/6089970.html
Https://www.cnblogs.com/hanxiaoyu/p/5549212.html
54178770
7035684
First assignment: In-depth analysis of Linux system processes