当前位置:网站首页>Process, time slice, concurrency and parallelism
Process, time slice, concurrency and parallelism
2022-06-10 04:26:00 【little-peter】
3.1 Preliminary understanding of the process
- For the operating system , A task is a process (Process).
- Textbook concept : An execution instance of a program , The program being executed, etc .
- Kernel view : Responsible for allocating system resources (CPU Time , Memory ) Entity of .
- How to understand the process ?
Such as : Zhang San goes to the bank to transfer money , Use the bank's resources ( Reception , Transfer personnel , Bank computer , If necessary, the security guard can also follow :) )
Complete the transfer for Zhang San , And inside the bank , The execution of this whole process , We are collectively referred to as handling business .
analogy , A program is a program on the hard disk at the beginning , Load runtime , To accomplish certain tasks ( If Xunlei finishes downloading
Mission ), And to complete the task , You need the operating system to provide enough resources for this task ( Such as memory and CPU resources ), And this whole
The execution of a set of tasks , We can call it a process
therefore : The process is responsible for allocating system resources (CPU Time , Memory ) Entity of , It has dynamic characteristics , For example, Zhang San is handling the transfer business
Service period , In this way, the task always exists and the state changes .
You can transfer money to the bank... Not immediately , You need to draw the number first , Wait in the hall , Because there may be many people waiting in the hall
stay , So there is the process waiting queue . And the number drawn by Zhang San , It can be called a process ID
below , We try to view the system process
Write a java process
public class Test {
public static void main(String[] args) throws Throwable {
Thread.sleep(99999999);
}
}
stay cmd Compile and run :
javac Test.java
java Test
After running, it will start java Program ( process ), You can view the process in the task manager

there PID The code representing this process , And our legendary java virtual machine , In essence, it is just a process in a system . For details, see the previous sample diagram
3.2 Time slice
Modern operating systems like Mac OS X,UNIX,Linux,Windows etc. , All support. “ multitasking ” Operating system of . The so-called multiple posts
service , The operating system can run multiple tasks at the same time .
operating system ( Such as Windows、Linux) Task scheduling is based on Time slice revolves Preemptive scheduling , That is to say, a task
After a short period of execution, force a pause to perform the next task , Each task is executed in turn .
A short period of time during which a task is performed is called Time slice , The status when the task is executing is called Running state , Forced pause after task execution for a period of time
Go to the next task , The suspended task is in Ready state 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 is very short , Quickly switch between tasks
in , The feeling is that there are multiple tasks “ At the same time ”, This is what we call Concurrent .
How to understand ?
Suppose Zhang San is going to handle the transfer business , But when he gave all the information to the staff , The staff told him , You can't handle it now ,
Because now he needs to fill out an application form , here , The staff kept his data , Ask him to fill in the information , Complete
After that , Come back and continue to handle , meanwhile , Zhangsan has gone to fill in the form , And the staff continue to provide services to others . This process is called a process
Switch .
Three forms have been filled out , Go back to the counter , The staff took out his previous information , Continue to handle business for Zhangsan , This is called up and down the process
Protection and restoration of cultural relics ( Think , Why do you do this ? Because the process is running in CPU Upper ,CPU There are registers , Save the process
Various temporary data for operation , In order to achieve the purpose of switching and easy recovery , There will be CPU How to save and restore registers , In the final analysis
The end result is to continue running at the last position )
later , The bank has issued regulations , Each person should not spend more time at the counter than 10 minute ( To prevent others from waiting for a long time ),
So in order to better serve all personnel , Bank staff applied the above idea of switching and recovery to various businesses , So long term
Look at , Even if there is only one staff member , It can also serve multiple customers at the same time , This mechanism is called time slice based process rotation manager
system , While the above 10 minute , It is the time slice of bank rotation , As long as the time comes , The customer waited for the wine , Let other users handle
Business
And all the above rotation and management work , In the operating system , Unification is done by a kernel module called the scheduler
And for everyone , In a period of time , Maybe everyone's business can be promoted ( Even if it's not done ), But not for a long time
Wait between , This mechanism is called concurrency
If the bank is rich and powerful , There are more staff than customers , That's easy , One person, one staff , All the tasks are really at the same time
The reason is , This mechanism is called parallelism .
below , Let's look at the detailed concepts of concurrency and parallelism
3.3 Concurrency and parallelism
Now? , Multicore CPU It's very popular , Because the number of tasks is far more than CPU The number of cores , therefore , The operating system will automatically
Many tasks are scheduled to execute on each core in turn . about
- Concurrent : Multiple processes in one CPU Time slice rotation is adopted under , In a period of time , Let multiple processes move forward , Call it concurrency .
- parallel : Multiple processes in multiple CPU Lower division , Run at the same time , This is called parallelism .
In the computer operating system, parallelism and concurrency are clearly distinguished , Mainly from the micro point of view , Specifically, it refers to the parallelism of processes
( In the case of multiprocessors , Multiple processes running at the same time ) And concurrency ( In the case of a single processor , Multiple processes run at the same time interval
Yes ).
Concurrency and parallelism are similar to pipelining in a factory , To expand production ,1 Is to consider building multiple factories , This is parallel ,2 Is to consider every worker
New assembly lines in the plant , This is similar to concurrency .
3.4 Kernel state and user state
General operating system ( Such as Windows、Linux) Level the execution authority : User mode and kernel mode .
As shown in the figure above , The operating system kernel is the underlying software that directly controls the hardware devices , The highest authority , Called kernel state , Or core
state .
The user program has the lowest permissions , It is called user mode .
How to understand ?
Just like the example above , Zhangsan goes to fill in the form , Write your own name , Telephone , Mailbox and so on , Do your own thing , This is called user mode
And Zhang San passed through the staff of the window , Give your needs to the staff , Since then , Zhangsan is waiting , The bank staff are busy , Yes, Zhang San
Speaking of , It's called getting into the kernel . So what does kernel state mean ? It is the status of the staff when they help you with your business
3.5 Context in process
The context is simply an environment , When the process rotates and switches in the time slice , Because each process runs in a different environment , It involves transformation
Context switching before and after
- When a process is executing ,CPU The values in all registers of 、 The state of the process and the contents on the stack .
- When switching, you need to save all the states of the current process , Save the process context of the current process , So that when the process is executed again , Able to restore the state when switching , Carry on
3.5 Process status

边栏推荐
- [深入研究4G/5G/6G专题-31]: 5G NR开机流程5.2 - UE Attach流程(Registeration Request/Accept/Complete)
- idea中怎样编写Scala代码
- Puzzling color deviation of unity illumination black
- 497. 非重叠矩形中的随机点
- [in depth study of 4g/5g/6g topic-23]: 5g NR startup process 4.1 - scheduling of the first uplink channel between MSG1 and PRACH and detection of time advance ta
- [Android L]SEAndroid增强Androd安全性背景概要及带来的影响
- Storage engine of MySQL database
- Huawei, this is too strong
- AI candidates challenge the composition of the college entrance examination, generating one essay in one second on average, with the level of more than 75% of the candidates
- IO被谁吃了?
猜你喜欢
![[science and technology specialty-3]: how many students with science and technology specialty know about the senior high school entrance examination](/img/a6/f0a2f8dafffa28d2b2d2cd0431b739.jpg)
[science and technology specialty-3]: how many students with science and technology specialty know about the senior high school entrance examination

Difference and idempotency analysis between put and patch in rest API

Encrypting CEPH RBD using luks2

Fastapi-16-page beautification-1
![[机缘参悟-18]:儒释道,不同人生阶段,不同选择](/img/3c/68eec2d6e29b703d2182b4cbba91e1.png)
[机缘参悟-18]:儒释道,不同人生阶段,不同选择

多商户商城小程序源码有何优势?

CVPR 2022 | indirect lighting modeling in inverse rendering
![[科技特长-3]:中考科技特长生知多少](/img/a6/f0a2f8dafffa28d2b2d2cd0431b739.jpg)
[科技特长-3]:中考科技特长生知多少

Fastapi-15-file upload-3

Use 80% of the charts to meet daily work, and use the remaining 20% of the charts to build core competitiveness!
随机推荐
libc、glibc和glib的关系
[science and technology specialty-1]: overview and advantages of science and Technology Specialty Students
[in depth study of 4g/5g/6g topic -24]: 5g NR startup process 4.2 - scheduling process and uplink synchronization of random access response message msg2, and time advance TA are sent through PDSCH cha
分布式数据对象:超级终端的'全局变量'
[laser principle and application-1]: what is a laser and its common applications
Two modes of epoll and epoll reactor
Yyds dry goods inventory solution sword finger offer: rectangular coverage
[机缘参悟-21]:以系统架构的角度重新思考技术、管理、打工、创业、投资
Metersphere | a super easy-to-use open source testing platform
[机缘参悟-18]:儒释道,不同人生阶段,不同选择
[cloud native | kubernetes] in depth understanding of pod (VI)
Jmeter测试TCP百万连接
91. fence
Design product use
Execution strategy of application software efficiency test
超好用的 Chrome 插件!
深度学习与CV教程(13) | 目标检测 (SSD,YOLO系列)
[科技特长-3]:中考科技特长生知多少
What are the advantages of multi merchant mall applet source code?
Lit (I): create components