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!

Bytecodeachievesplatformindependencebybeingexecutedbyavirtualmachine(VM),allowingcodetorunonanyplatformwiththeappropriateVM.Forexample,JavabytecodecanrunonanydevicewithaJVM,enabling"writeonce,runanywhere"functionality.Whilebytecodeoffersenh

Java cannot achieve 100% platform independence, but its platform independence is implemented through JVM and bytecode to ensure that the code runs on different platforms. Specific implementations include: 1. Compilation into bytecode; 2. Interpretation and execution of JVM; 3. Consistency of the standard library. However, JVM implementation differences, operating system and hardware differences, and compatibility of third-party libraries may affect its platform independence.

Java realizes platform independence through "write once, run everywhere" and improves code maintainability: 1. High code reuse and reduces duplicate development; 2. Low maintenance cost, only one modification is required; 3. High team collaboration efficiency is high, convenient for knowledge sharing.

The main challenges facing creating a JVM on a new platform include hardware compatibility, operating system compatibility, and performance optimization. 1. Hardware compatibility: It is necessary to ensure that the JVM can correctly use the processor instruction set of the new platform, such as RISC-V. 2. Operating system compatibility: The JVM needs to correctly call the system API of the new platform, such as Linux. 3. Performance optimization: Performance testing and tuning are required, and the garbage collection strategy is adjusted to adapt to the memory characteristics of the new platform.

JavaFXeffectivelyaddressesplatforminconsistenciesinGUIdevelopmentbyusingaplatform-agnosticscenegraphandCSSstyling.1)Itabstractsplatformspecificsthroughascenegraph,ensuringconsistentrenderingacrossWindows,macOS,andLinux.2)CSSstylingallowsforfine-tunin

JVM works by converting Java code into machine code and managing resources. 1) Class loading: Load the .class file into memory. 2) Runtime data area: manage memory area. 3) Execution engine: interpret or compile execution bytecode. 4) Local method interface: interact with the operating system through JNI.

JVM enables Java to run across platforms. 1) JVM loads, validates and executes bytecode. 2) JVM's work includes class loading, bytecode verification, interpretation execution and memory management. 3) JVM supports advanced features such as dynamic class loading and reflection.

Java applications can run on different operating systems through the following steps: 1) Use File or Paths class to process file paths; 2) Set and obtain environment variables through System.getenv(); 3) Use Maven or Gradle to manage dependencies and test. Java's cross-platform capabilities rely on the JVM's abstraction layer, but still require manual handling of certain operating system-specific features.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment
