当前位置:网站首页>Understanding process (multithreading primary)
Understanding process (multithreading primary)
2022-04-23 02:25:00 【Bug Guo】
Catalog
In this section, the target
- The process of understanding
- Understand the properties and management of the process
- Difference between process and thread
The process of understanding
What is the process !!!
process (
Process) A program in a computer is about a running activity on a data set , yesThe basic unit of resource allocation and scheduling, yesThe foundation of the operating system structure. In early process oriented computer architecture , A process is the basic execution entity of a program ; 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 .
Simply put, it's a running application (exe) Is the process !!!
There are many on our computer disk exe file , If we double-click this exe file , Then this file will only lie quietly on the disk, just like salted fish !!!

Only exe file ( Executable file ) Only after running can it be called a process !!!
We can turn on our computer task management , Look at the processes running on our operating system at this time !!!

An execution file (exe) How does it become a process ?
- At first... On disk
exefile - After running, the operating system allocates and schedules resources !
- Load the file into memory
cpuStart executionexeSome instructions in
Threads
What is the thread we often hear about ? What does it have to do with the process ?
Threads ( English :
thread) It is the smallest unit that the operating system can schedule operations . It is included in the process , Is the actual operation unit in the process .A thread refers to a single sequential control flow in a process , Multiple threads can be concurrent in one process , Each thread performs different tasks in parallel. stay Unix System V And SunOS It's also calledLightweight process (lightweight processes, But lightweight processes are more about kernel threads (kernel thread), And put the user thread (user thread) Called thread .
We know that process is the basic unit of operating system resource allocation and scheduling !!!
For example, process is a factory in our life !! Thread is the workshop or assembly line in the factory !!!
A factory can have one or more assembly lines !
A process can also contain one or more threads !!!
Thread is the smallest unit of operation scheduling !!!
That is to say , The operating system needs to allocate resources and space to the process , Multiple threads share this space and resources !
process process Also known as task Mission ! Task management system , That is, the process management system of our operating system !!!
Process properties and management
How computers manage processes ?
First we need to describe a process ( Identify some important attributes of the process )
Then organize multiple threads ( Use data structure to put multiple process description information together for addition, deletion, query and modification )
Our processes are allocated and scheduled by the operating system !
The operating system is made up of C/C++ Compiling !
We describe the properties of the process through the structure
Then organize several processes through a two-way linked list , You can add, delete, check and modify !!!
Process properties
Basic properties
We know that each of us has our own name and characteristics ! And so is the process !
Each process has its own attributes to distinguish different processes !!!
PCB
To describe the operation of the control process ,
The data structure in which the process management and control information is stored in the system is called process control block(PCB Process Control Block), It's part of the process entity , Is the most important recorded data structure in the operating system . It is the most important data structure for process management and control , Each process has a PCB, When creating a process , establish PCB, The whole process accompanying the process , Until the process is undone .
We go through PCB You can know the information of this process !
pcb Some properties in
pid
processidIdentify the process !- Memory pointer
Indicate the specific location of the instructions and code or resources to be executed by the process in memory - Document descriptor table
A process may be associated with multiple other files , Provide resources to the process , So we need to know which files will be used in this process ! After opening a file , A message will be added to the file descriptor table , The file descriptor table can be treated as an array , The element is a structure !
Our process will open three files by default ( The system opens automatically ):
The standard input (System.in)
standard output (System.out)
The standard error (System.err)
Implement the properties of process scheduling
Concurrency and parallelism
When we mention process scheduling, we have to mention concurrency and parallelism !
We know the of today's computers cpu They all use multiple cores cpu!
One cpu The core can only execute one process at a time !!!
But many cpu The core can execute different processes at the same time ! This is parallel !
On the micro :
parallel : Every cpu The core performs different tasks at the same time !
Concurrent : One cpu The core performs the task first 1, On mission 2!!!
But we know that cpu The execution speed is faster than you think ! Fast batch !
Therefore, from a macro perspective, we can't feel whether the process is executed concurrently or in parallel at a certain time ! Usually we call concurrency and parallelism Concurrent We're just working on the operating system , Distinguish the two , We call it concurrency by default in other places !!!
- state
This state describes how the process is scheduled
Ready state : AnytimeCPUperform
Blocked state / Sleep state : You can't take up timeCPUperform
There are other states that will be introduced later ! - priority
Our computer usually executes multiple processes concurrently
Then you need to clarify the priority of a process
First assign time to that process , How much time is allocated !
And who allocated how much time ! - Billing information
Count the execution time of each process , Executed those instructions separately !
How long did you wait , Provide basis for process scheduling ! - Context
Record the last process dispatchCPUThe execution state of the !
Our process cannot go on forever , When ourCPUWhen other processes need to be scheduled , Then the process will come outcpu, When we need to execute the process again , The context attribute can be accurately restored to the location of the last process execution !
It's called out in the processCPUwhen , Let's save the data in the register in memory ( The archive ), The register is called back the next time the process executes ( Reading )
Let's give a real-life example to understand the above process scheduling properties !
If there is a sea king ( operating system )
The sea king also talked about 3 Objects !!!
A rich woman
A hot girl
A sweet girl
We know that this operation is obviously immoral ! But as long as this 3 It's not a big problem if an object doesn't meet. Haiwang just needs to arrange to make an appointment with a sister at a certain time !( That is, macroscopically cpu Only one process was executed )
If sea king prefers hot girls , Then the rich woman , Finally, sweet sister ( Cute is not worth mentioning in front of sexy )( Here is the priority of the process )
Monday, Tuesday, Wednesday With hot girls
Thursday and Friday With a rich woman
Saturday With sweet sister
Rest on Sundays
Under normal circumstances , Three girls are on call ( That is, the process is ready )
As a result, the spice girl went on a business trip for a month and couldn't come back !!( At this point, the process is in a blocked state / Sleep state )
Sea King and sweet sister spend too little time , Sweet sister doesn't want to ( Process accounting information archiving )
So at this time, sea king will arrange more time for sweet sister !!!
When one day , The rich woman said she would take the sea king to talk about her parents , The spice girl said she would take him to her best friend , All told him to prepare gifts ! As a result, Haiwang gave the gift to the rich woman's parents , Hot girl best friend ! If recorded ( Process context properties ) There will be no mistake !!!
Obviously, the sea king is wrong !!! Make people despise !!!
Process scheduling
Whether in batch system or time-sharing system , The number of user processes is generally more than the number of processors 、 This will cause them to compete with each other . in addition , System processes also need to use processors . This requires the process scheduler to follow a certain policy , Dynamically assign the processor to a process in the ready queue , To make it perform .
Namely cpu How to allocate resources to a process !
We know that each process allocates its own space ! however cpu, Limited memory resources !!!
When one of our processes goes out bug Because in different spaces , It won't affect other processes !
Independence of the process
Like the current epidemic

If a resident is infected , Then just block the building !!!( The process appears bug 了 ) It won't affect other processes !!!
Interprocess communication
But it is clear that processes cannot always be independent , No communication ,cpu Some public space will be allocated for the process to communicate !!!
There are two main modes of communication :
- File operations
- Network operating (
socket)
Later we will introduce !!!
Difference between process and thread
High frequency interview questions
- Process is the basic unit of system resource allocation !
- Thread is the smallest unit of system scheduling !
- A process contains one or more threads !
- Processes and threads are designed to handle concurrent programming !
Process shortcomings , Less efficient creation and destruction ( Resources need to be allocated ), Threads make up for this shortcoming !( Lightweight process ), A thread executes a piece of code !!! - Process independence , Each process will have its own virtual space ! If one process hangs, it will not affect another process !
But a process has multiple threads , One thread hangs, which may affect other threads , Even lead to the collapse of the process !!!
版权声明
本文为[Bug Guo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230222599249.html
边栏推荐
- openstack 服务的启动
- IAR embedded development stm32f103c8t6 Lighting LED
- 简洁开源的一款导航网站源码
- The 16th day of sprint to the big factory, noip popularization Group Three Kingdoms game
- easyswoole环境配置
- tp6阿裏雲短信 window 報 cURL error 60: SSL certificate problem: unable to get local issuer certificate
- RT_Thread自问自答
- Go language ⌈ mutex and state coordination ⌋
- 小程序 读取文件
- 今天终于会写System.out.println()了
猜你喜欢

Common formatting problems after word writing

RT_Thread自问自答

How many steps are there from open source enthusiasts to Apache directors?

【汇编语言】从最底层的角度理解“堆栈”

arduino esp8266 网络升级 OTA

PTA: 点赞狂魔
智能辅助功能丰富,思皓X6安全配置曝光:将于4月23日预售

都是做全屋智能的,Aqara和HomeKit到底有什么不同?

World Book Day 𞓜 a good book that technicians should not miss (it cutting-edge technology)

Wechat public platform test number application, authorized login function and single sign on using hbuilder X and wechat developer tools
随机推荐
How does Axure set the content of the text box to the current date when the page is loaded
007_Redis_Jedis连接池
New book recommendation - IPv6 technology and application (Ruijie version)
每日一题(2022-04-22)——旋转函数
Synchronized锁及其膨胀
手写内存池以及原理代码分析【C语言】
PTA: 浪漫倒影 [二叉树重建] [深度优先遍历]
不断下沉的咖啡业,是虚假的繁荣还是破局的前夜?
Program design: l1-49 ladder race, allocation of seats (simulation), Buxiang pill hot
Daily question (April 22, 2022) - rotation function
Latin goat (20204-2022) - daily question 1
Open3d point cloud processing
RT_ Thread ask and answer
Network jitter tool clumsy
ThinkPHP kernel development blind box mall source code v2 0 docking easy payment / Alibaba cloud SMS / qiniu cloud storage
假如404页面是这样的 | 每日趣闻
After idea is successfully connected to H2 database, there are no sub files
Common formatting problems after word writing
【ValueError: math domain error】
012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)