当前位置:网站首页>1. Threads and processes
1. Threads and processes
2022-07-18 19:55:00 【123_ YQH】
Threads
1. Thread and process overview
① Similar to the process , Threads are a mechanism that allows applications to perform multiple tasks concurrently . A process can contain multiple threads . All threads in the same program will execute the same program independently , And Share the same global memory area , This includes initializing data segments 、 Uninitialized data segment (BSS paragraph ), And heap memory segments .
② The process is CPU The smallest unit of allocation of resources , Threads are the smallest unit of scheduling execution in the operating system .
③ Threads are lightweight processes , stay LInux In this environment, the essence of thread is still process .
④ View the... Of the specified process LWP( Threads ) Number : ps -Lf pid
Such as : stay unbuntu Open Firefox in .
perform ps aux The process of checking Firefox browser is 42569
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-LuWT4B4W-1657785561256)(C:\Users\ThinkStation K\AppData\Roaming\Typora\typora-user-images\1657783228477.png)]](/img/4c/93c1289106c6bf315173867140fc52.png)
Input :ps -Lf 42569 Get the thread opened in the Firefox browser process .
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-nHb3EJJp-1657785561257)(C:\Users\ThinkStation K\AppData\Roaming\Typora\typora-user-images\1657783342343.png)]](/img/62/b0948448d4c11687ca810411fce81f.png)
2. Thread is different from process
There are several differences :
- Information between processes is difficult to share . Because except for the read-only code segment , The parent-child process does not share memory , Therefore must Adopt some process communication methods , Exchange information between processes .
- call fork() The cost of creating a process is relatively high , Even with Share while reading , Copy on write technology , You still need to copy a variety of process attributes such as memory page tables and file descriptors , It means fork() The time cost of calling is still expensive .
- Threads can be easily 、 Share information quickly . Just copy the data to the share ( Global or heap ) Variable .
- Creating threads is faster than creating processes 10 Times or more . Inter thread time Sharing virtual space , No write time assignment is needed to copy memory , There is no need to copy the page table .
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-GQI2JL6s-1657785561257)(C:\Users\ThinkStation K\AppData\Roaming\Typora\typora-user-images\1657784838746.png)]](/img/cf/297901207589302e0618439125b107.png)
边栏推荐
- 3.终止线程
- Vivado ROM IP核
- Behavioral model summary
- 2.创建线程
- Android day 27: database one
- 7.9 hash table (hash table)
- 第一章 FPGA数字信号处理_数字混频(NCO与DDS)
- 安利一款笔记工具---Obsidian
- Full marks for all! The Chinese team IMO won four consecutive titles, leading the second place South Korea by a big score
- Horizon 8 测试环境部署(6): UAG 负载均衡配置-2
猜你喜欢

Foreigners still stayed 20 years ago
![[200 opencv routines] 232 Spectral method of feature description](/img/54/77f420654cc49723fbdbe845023ec8.png)
[200 opencv routines] 232 Spectral method of feature description

The third part of building PSIM simulation model of buck circuit (simulation of digital difference equation)

Mina中的支付交易snark

Change signal sampling rate and measurement mean frequency, power and bandwidth

Anaconda installation (very detailed)

Vivado ROM IP core

Full power travel Wang Ying: Escort smart travel with data security

公司股权分配参考

Horizon 8 test environment deployment (5): UAG deployment and load balancing configuration-1
随机推荐
【读书会第13期】+FFmpeg项目组成
Dark horse programmer - software testing -14 stage 3- function testing -66-77 Zen introduction, product manager uses Zen, super administrator uses Zen, super administrator modifies security strategy,
Anaconda安装(非常详细)
Behavioral model summary
罗永浩:或2年后举行首场发布会,2000人年代码量是护城河
vivado之COE文件使用方法
9、 MySQL locking mechanism X. replication
Machine learning: cross entropy from theory to code
Unity video control pause playback and slider drag (notes)
[wechat applet] page configuration, network data request
Vivado ROM IP core
1.自制脚本语言-第一章笔记
Aike AI frontier promotion (7.16)
Anaconda installation (very detailed)
2.Markdown使用说明
5道String高频面试题,拿捏String底层原理!
Dark horse programmer - software testing -15 stage 3- function testing 146-173 case review summary, tpshop project practice, state transition method cases, flow chart, business process testing, relati
中科大少年班录取名单公布:浙江狂揽三成名额,仅学军中学就有4人
Horizon 8 test environment deployment (5): UAG deployment and load balancing configuration-1
[MySQL project practical optimization] convert multiple rows of data into the same row and multiple columns for display