当前位置:网站首页>多进程编程(五):信号量
多进程编程(五):信号量
2022-07-02 23:05:00 【HDD615】
参考链接:信号量
进程间通信方式的区别
1、首先最简单的就是管道,管道又分为匿名管道和有名管道
匿名管道只能用于具有亲属关系的进程间通信,单向传输;如果想要双向通信,就要设置两个管道;匿 名管道是一种特殊的文件,存在内核中的缓冲区,传输数据是无格式的字节流数据,大小受限制。
而有名管道,通过在文件系统中创建文件的方式,解决了匿名管道只能用于具有亲属关系的进程通信的 问题,从而无关系的进程也可以进行通信。
2、消息队列,实际上是内核中的一个消息链表,它克服了管道通信数据是无格式的字节流的问题。但是消息队列的通信速度不及时,因为每次数据的写入和读取都要经过用户态和内核态的拷贝
3、共享内存,通过直接在内存中分配一个共享内存空间,解决了数据拷贝的问题,多个进程都可以通过地址来直接访问这块共享的内存空间,但是多个进程同时竞争可能会出现数据的错乱
共享内存是最高效的一种方式
4、信号量,是一种进程同步的一种手段,可以用来保护共享资源,确保任一时刻只有一个进程在访问共享资源。
通常用来和共享内存一块使用,也就是在获得锁之后,再对共享内存进行操作(写/读)
边栏推荐
猜你喜欢

论文的英文文献在哪找(除了知网)?

Practical series - free commercial video material library
![洛谷_P2010 [NOIP2016 普及组] 回文日期_折半枚举](/img/a3/55bb71d39801ceeee421a0c8ded333.png)
洛谷_P2010 [NOIP2016 普及组] 回文日期_折半枚举

95 pages of smart education solutions 2022

Monitor container runtime tool Falco

Custom throttling function six steps to deal with complex requirements

Create an interactive experience of popular games, and learn about the real-time voice of paileyun unity

Mutual exclusion and synchronization of threads

Maya fishing house modeling
![[shutter] open the third-party shutter project](/img/1a/e35d0180612d7e79b55e7818193740.jpg)
[shutter] open the third-party shutter project
随机推荐
Bigder: how to deal with the bugs found in the 32/100 test if they are not bugs
Happy Lantern Festival, how many of these technical lantern riddles can you guess correctly?
Digital twin visualization solution digital twin visualization 3D platform
Confluence的PDF导出中文文档异常显示问题解决
Digital twin smart factory develops digital twin factory solutions
附加:token;(没写完,别看…)
Realization of mask recognition based on OpenCV
Xcode real machine debugging
MFC file operation
[shutter] image component (image component introduction | image constructor | image.network constructor | image.asset constructor)
130 pages of PPT from the brick boss introduces the new features of Apache spark 3.2 & 3.3 in depth
How to specify const array in the global scope of rust- How to specify const array in global scope in Rust?
来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能
In February 2022, the ranking list of domestic databases: oceanbase regained its popularity with "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
Interpretation of new plug-ins | how to enhance authentication capability with forward auth
Which websites can I search for references when writing a thesis?
leetcode 650. 2 Keys Keyboard 只有两个键的键盘(中等)
JDBC tutorial
监控容器运行时工具Falco
Analyze ad654: Marketing Analytics