当前位置:网站首页>Relationship between fork and pipeline
Relationship between fork and pipeline
2022-07-24 08:35:00 【Egg Prince】
First of all, let's understand fork After the implementation , Two processes will appear :

problem :fork Is used to create processes , The child process copies the same code as the parent process , But with the pipe Continuous time , Also copy pipe Do you ? It's a self-directed thing , Read something , How to realize interprocess communication ?
answer :
fork() Not only create a child process with the same code as the parent process , And the parent process is fork All context scenarios of the execution point are also automatically copied into the subprocess , Include :(1) Global and local variables (2) Open file handle (3) Shared memory 、 Synchronization objects such as messages .
because pipe Calling is equivalent to creating 2 File handles , So in fork The latter two handles are also automatically copied to the child process , The operation effect of these two handles is consistent with that of the main process , This makes it easy for parent-child processes to exchange data through this mechanism , for instance :
hypothesis pipe The resulting handle is P[0],P[1], stay fork After the father and son processes have P[0],P[1] Handle , that :
— The parent process can send its own P[1] Middle write data , Subprocesses from P[0] The data can be read out in ; Remember that the parent process cannot also start from P[0] Reading data , Otherwise, the data written by yourself may be read by yourself first
— vice versa , Subprocess to P[1] After data is written in , The parent process starts from P[0] This data can be read in ; Remember that the subprocess should not start from P[0] Read data .
You may not understand why the data read and write inside the process will be transferred to another process , But don't forget ,pipe Anonymous pipes and files ,socket And so on are the management objects of the operating system , It is read and written by OS Kernel code to control . Call... In the parent process pipe After creating the pipe , The pipeline object is stored in OS Inside , Obtained by the parent process P[0] and P[1] Are just references to this object ( Equivalent to pointer ); stay fork After the subprocess , The child process copies only the same pointer , It's still pointing to OS The same object in , This is why parent-child processes can communicate with each other through it .
————————————————
Link to the original text :https://blog.csdn.net/yizhou35/article/details/12288023
边栏推荐
- table-rowspan
- 3587. 连通图(吉林大学考研机试题)
- js获取当前浏览器的默认语言
- Kotlin learning note 1 - variables, functions
- 国产“火箭心”人工心脏上市 不同人工心脏有什么区别?
- Hack the box - Introduction to networking module detailed Chinese tutorial
- [Yum] configuration and use of Yum source
- 2022.7.11全盘题解
- The code is tired. Stop and enjoy the top color matching~
- Go: Gin basicauth Middleware
猜你喜欢

Okaleido tiger NFT is about to log in to binance NFT platform, and the era of NFT rights and interests is about to start

MySQL日期格式化

Shanghai issued a document to support the entry of NFT cultural exchange: the trend of digital collections has arrived!

Route interceptor

3587. Connected graph (Jilin University postgraduate entrance examination machine test question)

阻塞队列BlockingQueue 源码解析(ArrayBQ和LinkedBQ)
![[technical interview] how to introduce yourself](/img/2e/775e4ba577098f7465309f772ee591.png)
[technical interview] how to introduce yourself

Move protocol global health declaration, step into Web3 in sports

Typora提示【This beta version of Typora is expired, please download and install a newer version】的解决方案

Will Plato become the risk target of the meta universe? Platofarm has great opportunities
随机推荐
Ansible automatic operation and maintenance
Precautions for using kettle excel input
Sed add content after a line
SOA and microservice examples
Optimization of MySQL paging query
Learn the rxjs operator
Wxml template concise tutorial
"Solution" friend of Vulcan
【JDBC】JDBC经典面试题,持续更新中......
Play to earn: a new and more promising game paradigm in the future
网络情人
Musk responded that the brain has been uploaded to the cloud: already did it!
Wechat official account configures custom menu jump applet and automatically replies to jump applet
Treap
How difficult is it to build a digital collection platform?
[Game Collection] mobile phones are about to burst, and a collection of six high-quality pyGame games is coming ~ (source code attached)
【情感】何为“优秀”
「题解」带分数
Go: how to gracefully time out
Typescript -- Generic