当前位置:网站首页>Multithreading (I) processes and threads
Multithreading (I) processes and threads
2022-07-05 18:05:00 【Worry free*】
Catalog
2、 How the operating system manages processes
3、 ... and 、 Similarities and differences between process and thread
One 、 process
1、 What is a process
A process is an abstraction of the operating system for a running program , In other words , You can think of a process as a running process of a program .
In the file , We can often see some suffixes as .exe file , These documents are called " Executable file ". Once such documents are executed , The operating system will load the file into memory ,CPU Will execute some instructions inside this file , At this point, these running applications are processes .
2、 How the operating system manages processes
(1) Describe a process
Specify some related attributes of a process , Mainly through the use of the operating system c/c++ Of " Structure " To describe ( In the operating system, it is called process control block PCB).
(2) Several processes
Typical implementation : Use a two-way linked list to put the PCB String together , It is convenient to add, delete, check and modify
among ," Create a process " Is to create PCB, Then take it. PCB Add to the two-way linked list ;" Destruction process " Is to find the... On the linked list PCB, Delete from the linked list ;" View Task Manager " Is to traverse the linked list .
(3) Interprocess communication
Processes are independent of each other , But it can also interact through some means . The operating system provides many " public space "( Generally file operation and network operation ), process A Put data in public space , The process then B Then take it away , This is interprocess communication .
(4)PCB Some properties in
① pid: It's the process id, Process identification id.
② Memory pointer : Indicates the code to be executed by the process / Where are the instructions in memory , And where the data that the process depends on (.exe The operating system will put .exe Load into memory , Become a process ).
③ Document descriptor table : As long as every file opened by the process , An item will be added to the file descriptor table . The file descriptor table can be treated as an array , Each of these elements is a structure . A process just starts , The system will automatically open the standard input , standard output , Standard error three files .
④ state : Describes how the current process should be scheduled next .
Ready state : Can be executed at any time .
Blocked state : You can't go to... For the time being CPU On the implementation .
⑤ priority : When we have many tasks , Which task to allocate time to first , Which task will you assign time to ; Which task has more time , Which task has less time , That's the priority .
⑥ Billing information : Count how long each process has been executed 、 What instructions were executed 、 How long did you wait in line . Provide guidance for process scheduling .
⑦ Context : Indicates that the last time the process was scheduled CPU The state of , In the next process CPU You can return to your previous state when you , Then continue to execute . Similar to archiving + Reading .
The process is called out CPU Before , First of all CPU The data in all registers in is saved to memory , Equivalent to archiving
The next time the process is scheduled CPU When , It can be recovered from memory to register , Equivalent to reading files
(5) Process scheduling
Process scheduling : The process scheduler is the real core of the operating system , It is directly responsible for CPU The distribution of . All processes in the system are in CPU Running on , Process scheduling is their switch
Two 、 Threads
1、 What is thread
A thread is an internal part of a process , The process contains threads . If you think of the process as a factory , So thread is the production line inside the factory . A factory can have a production line , There can also be multiple production lines .
2、 Why have threads
Because the system supports multitasking , So we need to do " Concurrent programming ".
Although concurrent programming can also be achieved through multiple processes , But frequent creation / The cost of the destruction process is very high , And the cost of frequent scheduling process is also very high ( Because the creation process requires the application of resources , The destruction process requires the release of resources , This in itself is very inefficient )
resolvent : Using threads to implement concurrent programming . Threads are lighter , Each thread performs a task , You can also program concurrently . establish 、 The destruction 、 The cost of scheduling threads is lower than that of processes ( The process needs to apply for the release of resources , Threads are included in the process , Share the same resource with other threads , Re create threads without reallocating resources . But it's not that the more threads, the better , When there are few tasks , Multithreading will reduce efficiency )
3、 ... and 、 Similarities and differences between process and thread
1、 Processes contain threads . At least one thread per process exists , The main thread .
2、 There is no shared memory space between processes . Threads of the same process share the same memory space .
3、 Operating system creation process , To allocate resources to a process , Process is the basic unit of resource allocation in the operating system ;
Thread creation operating system , Is to be in CPU Scheduled execution on , Thread is the basic unit of operating system scheduling thread execution .
4、 The process is independent . Each process has its own virtual address space , There is a problem with a process , No impact on other processes . Multiple threads in the same process use the same memory space , If a thread has a problem , It is likely to affect other threads , It may also directly lead to problems in the whole process .
边栏推荐
- [paddleclas] common commands
- Generate classes from XML schema
- Easynmon Usage Summary
- U-Net: Convolutional Networks for Biomedical Images Segmentation
- 修复漏洞 - mysql 、es
- Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
- 《力扣刷题计划》复制带随机指针的链表
- 第十一届中国云计算标准和应用大会 | 云计算国家标准及白皮书系列发布 华云数据全面参与编制
- How to solve the error "press any to exit" when deploying multiple easycvr on one server?
- 较文心损失一点点性能提升很多
猜你喜欢
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
第十一届中国云计算标准和应用大会 | 云计算国家标准及白皮书系列发布 华云数据全面参与编制
Elk log analysis system
Why is all (()) true and any (()) false?
第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
Cmake tutorial Step4 (installation and testing)
Sophon base 3.1 launched mlops function to provide wings for the operation of enterprise AI capabilities
GFS分布式文件系统
Cmake tutorial Step2 (add Library)
Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具
随机推荐
怎么选择外盘期货平台最正规安全?
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
ISPRS2022/雲檢測:Cloud detection with boundary nets基於邊界網的雲檢測
第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
rsync
EPM related
图片数据不够?我做了一个免费的图像增强软件
ConvMAE(2022-05)
Zabbix
《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
How to improve the thermal management in PCB design with the effective placement of thermal through holes?
ISPRS2022/云检测:Cloud detection with boundary nets基于边界网的云检测
第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
LeetCode 练习——206. 反转链表
rsync
Cmake tutorial step1 (basic starting point)
Sophon AutoCV:助力AI工业化生产,实现视觉智能感知
记一次使用Windbg分析内存“泄漏”的案例
第十一届中国云计算标准和应用大会 | 云计算国家标准及白皮书系列发布 华云数据全面参与编制
Compared with the loss of Wenxin, the performance is improved a lot