当前位置:网站首页>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 .
边栏推荐
- [Tang Laoshi] C -- encapsulation: classes and objects
- 大型网站如何选择比较好的云主机服务商?
- Promotion hung up! The leader said it wasn't my poor skills
- Jvxetable用slot植入j-popup
- 注释、接续、转义等符号
- First acquaintance with CDN
- [detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
- How to download GB files from Google cloud hard disk
- LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
- Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
猜你喜欢
Cuda11.1 online installation
Questions d'examen écrit classiques du pointeur
ArcGIS应用基础4 专题图的制作
Vulhub vulnerability recurrence 67_ Supervisor
Check the useful photo lossless magnification software on Apple computer
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
B站刘二大人-线性回归 Pytorch
How to use PHP string query function
(column 22) typical column questions of C language: delete the specified letters in the string.
ARTS Week 25
随机推荐
【华为机试真题详解】检查是否存在满足条件的数字组合
js Array 列表 实战使用总结
B站刘二大人-线性回归 Pytorch
Quantitative description of ANC noise reduction
Zoom and pan image in Photoshop 2022
JDBC calls the stored procedure with call and reports an error
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
Migrate Infones to stm32
Notes, continuation, escape and other symbols
[detailed explanation of Huawei machine test] statistics of shooting competition results
Promise summary
B站刘二大人-数据集及数据加载 Lecture 8
[imgui] unity MenuItem shortcut key
Installation de la Bibliothèque de processus PDK - csmc
Fluent implements a loadingbutton with loading animation
【云原生】3.1 Kubernetes平台安装KubeSpher
UCF (2022 summer team competition I)
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
嵌入式面试题(四、常见算法)
指針經典筆試題