mean? Please provide more context.
1 Process Overview
The process is an abstraction of logic. We have a lot of understanding of the process from operating system books, but we may not know much about the implementation of the process. This article Try to explain the general principles of process implementation.
The implementation of the process is actually the same as when we usually write code. For example, if we want to represent something, we will define a data structure. Processes are no exception. So the essence of a process is a data structure, which stores a series of data. The operating system manages all processes in the form of arrays or linked lists. Processes can be said to be divided into two types
1 The first process when the system is initialized,
2 Except for the first process, other processes are created by the fork or fork execute system calls.
Let’s first take a look at the information in the process structure.

The above is the main information in the structure representing the process. Then a structure represents a process. We know that fork uses the parent process as a module, copies the structure of the parent process, and then modifies certain fields. It becomes a new process. If execute is called, the fields in the copied structure (such as page tables, code segments, and data segments) are further modified. And load the corresponding data from the hard disk to the memory. So how is the first process generated? Because a process is just a structure, if we predefine a structure, we can create a process without forking.
2 Process execution
When the system creates a process, it will set the value of the cs:ip register. If it is a fork, the ip is the statement after the fork function. ip address. If it is execute, the ip address is specified by the compiler. No matter what, when the process starts executing, the CPU will parse cs:ip and get an instruction to execute. So how is cs:ip parsed?
When the process is executed, the tss selector (GDT index) is loaded into the tss register, and then the context in tss is also loaded into the corresponding register, such as cr3, ldt selector. According to the ldt index in the tss information, first find the first address of the process ldt structure data from GDT, and then obtain the selector from cs according to the attributes of the current segment, such as the code segment, and the system obtains the first address of the process linear space from the ldt table. Address, length limit, permissions and other information. Use the first address of the linear address plus the offset in the IP to obtain the linear address, and then obtain the physical address through the page directory and page table. If the physical address has not been allocated, page fault exceptions and other processing will be performed.
3 Process suspension and wake-up
Process suspension, blocking, and multiple processes. We usually hear these concepts quite often, now let’s see how they are implemented. There are two types of process suspension or blocking.
1 Actively suspend. Let the process hang intermittently through sleep. The principle of sleep has been analyzed before, so I will not analyze it again. The general principle is to set a timer and wake up the process after expiration.
Modify the process to a suspended state and wait for wake-up.
-
2 Passive suspension.
There are many scenarios of passive suspension, mainly when the process applies for a resource, but the resource does not meet the conditions, then the process is suspended by the operating system. For example, when we read a pipe. If there is no data to read from the pipe, the process is suspended. Insert into the pipe's waiting queue.

<code>// 当前进程挂载到睡眠队列p中,p指向队列头指针的地址<br>void sleep_on(struct task_struct **p)<br>{<br> struct task_struct *tmp;<br><br> if (!p)<br> return;<br> if (current == &(init_task.task))<br> panic("task[0] trying to sleep");<br> /*<br> *p为第一个睡眠节点的地址,即tmp指向第一个睡眠节点<br> 头指针指向当前进程,这个版本的实现没有采用真正链表的形式,<br> 他通过每个进程在栈中的临时变量形成一个链表,每个睡眠的进程,<br> 在栈里有一个变量指向后面一个睡眠节点,然后把链表的头指针指向当前进程,<br> 然后切换到其他进程执行,当被wake_up唤醒的时候,wake_up会唤醒链表的第一个<br> 睡眠节点,因为第一个节点里保存了后面一个节点的地址,所以他唤醒后面一个节点,<br> 后面一个节点以此类推,从而把整个链表的节点唤醒,这里的实现类似nginx的filter,<br> 即每个模块保存后面一个节点的地址,然后把全局指针指向自己。<br> */<br> tmp = *p;<br> *p = current;<br> // 不可中断睡眠只能通过wake_up唤醒,即使有信号也无法唤醒<br> current->state = TASK_UNINTERRUPTIBLE;<br> // 进程调度<br> schedule();<br> // 唤醒后面一个节点<br> if (tmp)<br> tmp->state=0;<br>}<br><br>// 唤醒队列中的第一个节点,并清空链表,因为第一个节点会向后唤醒其他节点<br>void wake_up(struct task_struct **p)<br>{<br> if (p && *p) {<br> (**p).state=0;<br> *p=NULL;<br> }<br>}</code>
We found that the implementation of the process is similar to how we usually write code, which is to define the data structure and then implement the algorithm to operate the data structure. Of course, because it involves the underlying hardware, the implementation of the operating system is much more complicated than our code.
The above is the detailed content of mean? Please provide more context.. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.
