当前位置:网站首页>Processes and threads
Processes and threads
2022-04-23 02:52:00 【Bo0o2】
process
We all know that the core of computers is CPU, It does all the computing , And the operating system is the manager of the computer , It is responsible for task scheduling , Allocation and management of resources ,
Command the whole computer hardware ; An application is a program that has some function , Programs run on the operating system .
A process is a dynamic execution of a program with certain independent functions on a dataset , Is an independent unit of the operating system for resource allocation and scheduling , It's an app
The carrier of program running . Process is an abstract concept , There has never been a unified standard definition . The process is generally programmed by , Data collection and process control block are composed of three parts . The program is used to describe
Functions to be completed by the process , Is the instruction set that controls the execution of the process ; A data set is the data and workspace that a program needs to execute ; The program control block contains the description information and control information of the process
Is the only sign that a process exists
Characteristics of process :
dynamic : A process is an execution of a program , It's temporary , With a lifetime , It's dynamic , Dynamic extinction ;
concurrency : Any process can execute concurrently with other processes ;
independence : A process is an independent unit of the system for resource allocation and scheduling ;
Structural : The process is programmed by , Data and process control block are composed of three parts
Threads
There was no thread concept in early operating systems , A process is the smallest unit that has resources and runs independently , It is also the smallest unit of program execution . Task scheduling adopts time slice
Round robin preemptive scheduling , Process is the smallest unit of task scheduling , Each process has a separate block of memory , Make the memory address of each process isolated from each other .
later , With the development of computers , Yes CPU The demand is higher and higher , Switching between processes is expensive , Can't meet the requirements of more and more complex programs . So he invented
Thread , Thread is a single sequential control process in program execution , Is the smallest unit of program execution flow , Is the basic unit of processor scheduling and dispatching . A process can have one or
Multiple threads , Shared program memory space between threads ( That is, the memory space of the process ). A standard thread by thread ID, Current instruction pointer PC, Register and stack group
become . The process is composed of memory space ( Code , data , Process space , Open file ) And one or more threads .
The difference between a process and a thread
1. A thread is the smallest unit of program execution , The process is the smallest unit of resources allocated by the operating system ;
2. A process consists of one or more threads , Threads are different execution paths of code in a process
3. Processes are independent of each other , But each thread in the same process shares the memory space of the program ( Including code snippets , Data sets , Pile etc. ) And some process level resources ( Such as opening documents and letters
Number, etc. ), Threads within a process are not visible to other processes ;
4. Scheduling and switching : Thread context switching is much faster than process context switching
All in all , Threads and processes are abstract concepts , A thread is an abstraction smaller than a process , Threads and processes can be used for concurrency .
There was no thread concept in early operating systems , A process is the smallest unit that can have resources and run independently , It is also the smallest unit of program execution , It is equivalent to
There is only one thread in a process , Process itself is a thread . So threads are sometimes called lightweight processes
later , With the development of computers , The efficiency of context switching between multiple tasks is required more and more , Just abstract out a smaller concept - Threads , In general, there will be more than one process
( It can also be a ) Threads .
Task scheduling
The task scheduling of most operating systems adopts the preemptive scheduling mode of time slice rotation , In other words, after a task is executed for a short period of time, it is forced to pause to perform the next task , Every
Tasks are carried out in turn . A short period of time during which a task is performed is called a time slice , The status when the task is executing is called running status , After a task has been executed for a period of time, it is forced to pause for the next task , By
The suspended task is ready , Wait for the arrival of the next time slice that belongs to it . So that every task can be carried out , because CPU Very efficient implementation of , Time slice
Very short , Quickly switch between tasks , The feeling is that there are multiple tasks “ At the same time ”, This is what we call concurrency
Why not use multiple processes, but use multiple threads ?
Thread cheap , The thread starts faster , Exit faster , The impact on system resources is also relatively small . And threads share most of the core objects with each other (File Handle) Ownership
If you use multiple processes , But unexpected , And the test is difficult
版权声明
本文为[Bo0o2]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220717481456.html
边栏推荐
- First knowledge of C language ~ branch statements
- MySQL function syntax
- Planning code ROS migration POMDP prediction planning (I)
- Shell learning notes -- shell processing of output stream awk
- Modification du contenu de la recherche dans la boîte déroulante par PHP + MySQL
- Practical combat of industrial defect detection project (II) -- steel surface defect detection based on deep learning framework yolov5
- Chapter VII project communication management of information system project manager summary
- 【Hcip】OSPF常用的6种LSA详解
- Implementation of distributed scenario business operation log (based on redis lightweight)
- Log4j knowledge point record
猜你喜欢
Fashion MNIST 数据集分类训练
L2-006 树的遍历(中后序确定二叉树&层序遍历)
Implementation of distributed scenario business operation log (based on redis lightweight)
LeetCode 1450 - 1453
能做多大的单片机项目程序开发,就代表了你的敲代码的水平
php+mysql對下拉框搜索的內容修改
ROP Emporium x86_64 7~8题
重大危险源企业如何保障年底前完成双预防机制数字化建设任务
ROP Emporium x86_ 64 7 ~ 8 questions
[wechat applet] set the bottom menu (tabbar) for the applet
随机推荐
How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year
Les derniers noeuds K de la liste jz22
Suggestion: block reference sorting is in the order of keywords
Flink stream processing engine system learning (I)
Get together to watch (detailed version) eat a few cents a day
MySQL复杂查询使用临时表/with as(类似表变量)
Download the genuine origin Pro 2022 tutorial and how to activate it
Shell script learning -- practical case
Leangoo brain map - shared multi person collaborative mind mapping tool
PIP install shutil reports an error
Rhcsa second day operation
《信息系统项目管理师总结》第五章 项目质量管理
OCR识别PDF文件
C language 171 Number of recent palindromes
进阶上将程序员必备素质
L2-006 树的遍历(中后序确定二叉树&层序遍历)
魔王冷饭||#078 魔王答上海、南京行情;沟通指导;得国和打杀筛选;赚钱的目的;改变别人看法
B blocks of the 46th ICPC Asian regional competition (Kunming)
JZ22 鏈錶中倒數最後k個結點
Chapter VII project communication management of information system project manager summary