当前位置:网站首页>These process knowledge you must know
These process knowledge you must know
2022-07-29 06:00:00 【Code and thinking】
What is the process
A program in a computer is about a running activity on a data set , Is the system resource allocation and scheduling of the basic unit , Is the foundation of the operating system architecture . In modern thread oriented computer architecture , A process is a container for threads . A program is an instruction 、 Description of data and its organization , A process is an entity of a program . Official explanation , You can understand it without speaking in vernacular , It's rare , In the language of programmers , Program is a class , Processes are objects .
The origin of the process
The existence of anything has its inevitability , Then why is there a process ?
- In order to improve the efficiency of computer system . Enhance the parallel operation ability of various hardware in the computer system . The operating system requires that the program structure must meet the needs of concurrent processing . To this end, the concept of process is introduced
- Process is the core of the operating system , All operating systems based on multiprogramming are based on the concept of process
- Process is a powerful tool for designing and analyzing operating system
- Clearly depict the internal laws of dynamic systems , Effective management and scheduling of programs running into the main memory of a computer system
Characteristics of the process
- dynamic : The essence of a process is an execution of a program in a multiprogramming system , The process is dynamic , Dynamic extinction
- concurrency : Any process can be executed concurrently with other processes
- independence : A process is a basic unit that can run independently , At the same time, it is also an independent unit of system resource allocation and scheduling
- asynchrony : Due to the inter process constraints , Make the process execution intermittent , That is, processes are independent of each other 、 Advance at an unpredictable speed
Structure of process
- Program
- data
- Process control block
A program is the runnable code written by a programmer , Data is generated during program operation , The process control block is used to indicate the status of the process , Its function is to make a program that cannot run independently in a multiprogramming environment ( Contain data ), Become a basic unit that can run independently or a process that can execute concurrently with other processes . In addition, multiple different processes can contain the same program , A program in different data sets constitutes different processes , Can get different results , But in the process of execution , The program can't change .
What has the process gone through
When the user sends instructions to the operating system that I want to start the program , First establish a process instance by the operating system , Each process has its own virtual address 、 Process control block 、 Page table and other data structures , Program entry returned from loader ( Virtual address ) Start , Operating system commands CPU Execute instructions from this virtual address , Because the code is not added to memory ,CPU Find the mapped physical address from the page table , Read the code in the hard disk into the memory through the page missing exception processing , then CPU Modify page table status , Indicates that the code has been loaded into memory , At this time, from the program entry ( Virtual address ) Start execution , With execution , The code is slowly added to memory , Keep running , There will be a blockage in the middle 、 Pending status, etc , Finally it's over , Release all data in memory .
Address assignment of the process

Each process will allocate the same virtual address space , And the same virtual address space , In fact, the corresponding physical addresses are different , But it can also be the same , So this provides favorable conditions for interprocess communication , The specific corresponding physical address actually consists of CPU Of MMU Module management . The kernel space holds the code and data of the kernel .
Process management
Why need management ? We all know ,CPU Only one thing can be handled at a time , Only one process can be processed , And the process is definitely better than CPU More than one , So there are multiple processes using one CPU The situation of , So the significance of process management lies in the rational allocation of computer resources , The resources here include CPU、 The Internet 、 Keyboard, etc , How reasonable ? You need to create and release at the right time , Reasonable pit occupation is the basic morality of a process . How many states does a process usually have ? as follows
Process life cycle
- Running state
- Sleep state
- Wait state
- New state
- A dead state
The conversion process of the above states is as follows :

The significance of process state is that it tells us , What can it do now , Especially for the operating system dad , It will load or release resources according to different states of the process , To avoid waste , Then we need a mechanism to accomplish such things , That is, the following process scheduling
Process scheduling
Scheduling means being dominated , To put it bluntly, it is dominated by the system with some algorithm , Of course, the success or failure of the algorithm , It is directly related to the throughput of the process 、CPU utilization 、 Fairness of resource acquisition , Scheduling algorithm is extremely complex , But there is a simple algorithm rule you must have heard , That is the priority algorithm , Always select the process with the highest priority , As the next running process , But when the highest priority process is not found , What to do ? Who should run at this time ? In fact, the system creates an idle process for us , If there is no idling process, can it ? answer : Can not be , Because the basic principle of process scheduling is to find the current process , Find the process to run , And then switch , If the current process is NULL, The next process to run is also NULL, How else can the scheduler execute ? It will cause the whole system to stop , Unable to continue . Speaking of process switching , Let's have a deep understanding :
Process switching
The most essential question is what has been switched ? Understand this , You will understand , Let me draw a picture , Help you understand

Each process corresponds to one PCB data structure , Used to store process control information , With this information, you can continue to run the next time you come back .PCB by Process Control Block Process control block , The data structure is as follows :
- Process status , No explanation
- pid, process ID, Uniqueness
- register , Generally, there are general registers 、 Instruction register , General access by user space , The instruction register stores the next instruction , In this way, you will know what to do when you resume operation
- priority , Priority of the process , The essence is right CPU Control priority size
- Communication information , Interprocess communication relationship , Communication channel provided by the operating system
- resources , Show the demand for resources , Like open files
- wait
There is no complete list , Because for different operating systems , There may be different data structures , So I won't list them one by one , I hope you can understand , The essence of process switching is to replace the current process object , It's just an object with the same class structure as him .
expand :
- The source power of process switching is the trap mechanism , Belonging to a kind of interruption , Interrupts are divided into hardware interrupts and software interrupts , For short, hard medium 、 Soft medium , Hard medium 45、 Soft medium 65, Um. … Can't afford , Soft is the trap mechanism , Traps themselves also need to be driven , Then its drive is ? If the program is abnormal , Illegal operation 、 The address is out of bounds 、 The breakpoint 、 Divide 0 wait .
- When it comes to interruptions , Have to mention , Interrupt is the only way from user mode to kernel mode , It's the only one .
author :i The headmaster
link :https://juejin.cn/post/7119117491330088967
边栏推荐
- A preliminary study on fastjason's autotype
- 【bug】XLRDError: Excel xlsx file; not supported
- Detailed explanation of MySQL statistical function count
- Laravel service container (Application of context binding)
- Reporting Services- Web Service
- Flink, the mainstream real-time stream processing computing framework, is the first experience.
- 主流实时流处理计算框架Flink初体验。
- 【比赛网站】收集机器学习/深度学习比赛网站(持续更新)
- How to obtain openid of wechat applet in uni app project
- Markdown语法
猜你喜欢

XDFS&中国日报社在线协同编辑平台典型案例

Synchronous development with open source projects & codereview & pull request & Fork how to pull the original warehouse

Simple optimization of interesting apps for deep learning (suitable for novices)

Training log 7 of the project "construction of Shandong University mobile Internet development technology teaching website"

通过简单的脚本在Linux环境实现Mysql数据库的定时备份(Mysqldump命令备份)

【Clustrmaps】访客统计

Lock lock of concurrent programming learning notes and its implementation basic usage of reentrantlock, reentrantreadwritelock and stampedlock

Training log 4 of the project "construction of Shandong University mobile Internet development technology teaching website"

How to obtain openid of wechat applet in uni app project

Flink, the mainstream real-time stream processing computing framework, is the first experience.
随机推荐
【目标检测】6、SSD
mysql在查询字符串类型的时候带单引号和不带的区别和原因
【Clustrmaps】访客统计
与张小姐的春夏秋冬(4)
Nifi changed UTC time to CST time
北京宝德&TaoCloud共建信创之路
SSM integration
NIFI 改UTC时间为CST时间
Spring, summer, autumn and winter with Miss Zhang (1)
Huawei 2020 school recruitment written test programming questions read this article is enough (Part 2)
Research and implementation of flash loan DAPP
Markdown syntax
anaconda中移除旧环境、增加新环境、查看环境、安装库、清理缓存等操作命令
iSCSI vs iSER vs NVMe-TCP vs NVMe-RDMA
yum本地源制作
"Shandong University mobile Internet development technology teaching website construction" project training log I
并发编程学习笔记 之 原子操作类AtomicReference、AtomicStampedReference详解
Laravel swagger add access password
Flink connector Oracle CDC 实时同步数据到MySQL(Oracle19c)
Reporting Services- Web Service