当前位置:网站首页>Embedded interview questions (I: process and thread)
Embedded interview questions (I: process and thread)
2022-07-06 05:40:00 【Sunspot ball】
One 、 Processes and threads
1、 What is a process 、 Threads , What's the difference? ?
Process is resource (CPU、 Memory, etc. ) Assigned base unit , Thread is CPU Basic units for scheduling and distribution ( The smallest unit of program execution ). At the same time , If CPU It's a single core , Only one process is executing , The so-called concurrent execution , It is also executed sequentially , Just because the switching speed is too fast , You think these processes are executing synchronously . Multicore CPU You can have multiple processes executing at the same point in time .
2、 Multi process 、 The advantages and disadvantages of multithreading
explain : A process is controlled by a process control block 、 Data segment 、 Code segment composition , The process itself cannot run programs , But like a container , First create a main thread , Allocate certain system resources to the main thread , At this time, you can start to implement various functions in the main thread . When we need to implement more complex functions , You can create multiple child threads in the main thread , Multiple threads in the same process , Use the system resources owned by this process to cooperate to complete some functions .
Advantages and disadvantages :1) The death of one process does not affect other processes , A thread crash is likely to affect the whole process in which it is located .2) The system cost of creating multiple processes is greater than that of creating multiple threads .3) Multi process communication because it needs to cross process boundaries , It is not suitable for the transmission of large amounts of data , It is suitable for the transmission of small data or dense data . Multithreading does not need to cross process boundaries , It is suitable for the transmission of a large amount of data between threads . And multithreading can share shared memory and variables in the same process .
3、 When to use the process , When to use threads
1) Create and destroy more frequently used threads , Because the creation process costs a lot .2) Requires a lot of data transfer using threads , Because multithreading switching is fast , There is no need to cross process boundaries .3) Secure and stable selection process ; Select threads quickly and frequently ;
4、 Multi process 、 Multithreading synchronization ( Communications ) Methods
Interprocess communication :
(1) Famous pipeline / Nameless pipe (2) The signal (3) Shared memory (4) Message queue (5) Semaphore (6)socket
Thread communication ( lock ):
(1) Semaphore (2) Read-write lock (3) Condition variables, (4) The mutex (5) spinlocks
5、 State transition diagram of process thread
(1) Ready state : The process has been granted except CPU All necessary resources outside , Just wait CPU State of . A system will arrange multiple processes in the ready state into a ready queue .
(2) Execution status : The process has been CPU, Being implemented . In a single processor system , There is only one process in the execution state ; In a multiprocessor system , There are multiple processes in execution state .
(3) Blocked state : The executing process cannot continue for some reason , And then abandon the processor and put it in a suspended state , That is, the process execution is blocked .( This state is also called waiting state or blocking state )
Typical events that usually cause a process to block are : request I/O, Apply for buffer space, etc .
commonly , Queue up blocked processes , Some systems also integrate these blocks into multiple queues according to different blocking causes .
(1) be ready → perform
A process in a ready state , When the process scheduler assigns a processor to it , The process changes from ready state to execution state .
(2) perform → be ready
A process in an execution state is in its execution , The processor had to be given up because one of the time slots allocated to it had run out , So the process changes from execution state to ready state .
(3) perform → Blocking
When an executing process cannot continue because it is waiting for an event to occur , From execution state to blocking state .
(4) Blocking → be ready
Blocked process , If the event it is waiting for has happened , So the process changes from blocked state to ready state .
6、 The parent process 、 Subprocesses
Parent process call fork() in the future , Clone a child process , A code snippet in which the child process and the parent process have the same content 、 Data segments and user stacks . Whether the parent process or the child process executes first is not necessarily , see CPU. So we usually set the parent process to wait for the child process to finish executing .
7、 Explain what context switching is ?
You can have many angles , There is a process context , There is an interrupt context .
Process context : When a process is executing ,CPU The values in all registers of 、 The state of the process and the contents of the stack , When the kernel needs to switch to another process , It needs 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 .
Interrupt context : Due to trigger signal , Lead to CPU Interrupt the current process , Turn to another program . Then all resources of the current process should be saved , Such as stack and pointer . After saving, execute the interrupt handler instead , After the fast read is executed, return to , After returning, restore the resources of the previous process , Carry on .
边栏推荐
- Deep learning -yolov5 introduction to actual combat click data set training
- 指针经典笔试题
- js Array 列表 实战使用总结
- UCF (summer team competition II)
- Codeforces Round #804 (Div. 2) Editorial(A-B)
- 【torch】|torch.nn.utils.clip_grad_norm_
- 剑指 Offer II 039. 直方图最大矩形面积
- Qt TCP 分包粘包的解决方法
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Codeforces Round #804 (Div. 2) Editorial(A-B)
猜你喜欢

JS array list actual use summary

B站刘二大人-线性回归及梯度下降
![[cloud native] 3.1 kubernetes platform installation kubespher](/img/86/137a65a5b58bc32e596d2a330ca9fc.png)
[cloud native] 3.1 kubernetes platform installation kubespher

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

05. Security of blog project

ArcGIS application foundation 4 thematic map making

数字经济破浪而来 ,LTD是权益独立的Web3.0网站?

ARTS Week 25

Redis消息队列

Unity Vector3. Use and calculation principle of reflect
随机推荐
C Advanced - data storage (Part 1)
Vulhub vulnerability recurrence 68_ ThinkPHP
Improve jpopup to realize dynamic control disable
What is independent IP and how about independent IP host?
嵌入式面试题(四、常见算法)
Unity Vector3. Use and calculation principle of reflect
27io stream, byte output stream, OutputStream writes data to file
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Modbus protocol communication exception
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Pix2pix: image to image conversion using conditional countermeasure networks
进程和线程
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
[experience] when ultralso makes a startup disk, there is an error: the disk / image capacity is too small
C进阶-数据的存储(上)
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
Notes, continuation, escape and other symbols
JS array list actual use summary
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
29io stream, byte output stream continue write line feed