search
HomeJavajavaTutorialmean? Please provide more context.
mean? Please provide more context.May 08, 2023 pm 10:16 PM
java

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.

mean? Please provide more context.

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.



When the pipe has content written, the process is awakened. The process is suspended (divided into two types: those that can be awakened by signals and those that cannot be awakened by signals) and the implementation of wake-up.
mean? Please provide more context.
<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!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
带你搞懂Java结构化数据处理开源库SPL带你搞懂Java结构化数据处理开源库SPLMay 24, 2022 pm 01:34 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

Java集合框架之PriorityQueue优先级队列Java集合框架之PriorityQueue优先级队列Jun 09, 2022 am 11:47 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于PriorityQueue优先级队列的相关知识,Java集合框架中提供了PriorityQueue和PriorityBlockingQueue两种类型的优先级队列,PriorityQueue是线程不安全的,PriorityBlockingQueue是线程安全的,下面一起来看一下,希望对大家有帮助。

完全掌握Java锁(图文解析)完全掌握Java锁(图文解析)Jun 14, 2022 am 11:47 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于java锁的相关问题,包括了独占锁、悲观锁、乐观锁、共享锁等等内容,下面一起来看一下,希望对大家有帮助。

一起聊聊Java多线程之线程安全问题一起聊聊Java多线程之线程安全问题Apr 21, 2022 pm 06:17 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

Java基础归纳之枚举Java基础归纳之枚举May 26, 2022 am 11:50 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

详细解析Java的this和super关键字详细解析Java的this和super关键字Apr 30, 2022 am 09:00 AM

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

Java数据结构之AVL树详解Java数据结构之AVL树详解Jun 01, 2022 am 11:39 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于平衡二叉树(AVL树)的相关知识,AVL树本质上是带了平衡功能的二叉查找树,下面一起来看一下,希望对大家有帮助。

java中封装是什么java中封装是什么May 16, 2019 pm 06:08 PM

封装是一种信息隐藏技术,是指一种将抽象性函式接口的实现细节部分包装、隐藏起来的方法;封装可以被认为是一个保护屏障,防止指定类的代码和数据被外部类定义的代码随机访问。封装可以通过关键字private,protected和public实现。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version