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

CMake基本使用

maya渔屋建模

附加:token;(没写完,别看…)

Bigder: how to deal with the bugs found in the 32/100 test if they are not bugs

Custom throttling function six steps to deal with complex requirements

Happy Lantern Festival, how many of these technical lantern riddles can you guess correctly?

Which websites can I search for references when writing a thesis?

容器运行时分析
![Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration](/img/a3/55bb71d39801ceeee421a0c8ded333.png)
Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration

Basic 10 of C language: array and pointer
随机推荐
Talk with the interviewer about the pit of MySQL sorting (including: duplicate data problem in order by limit page)
JS interviewer wants to know how much you understand call, apply, bind no regrets series
来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能
Interface automation coverage statistics - used by Jacobo
Custom throttling function six steps to deal with complex requirements
JVM foundation review
MySQL advanced learning notes (4)
Realization of mask recognition based on OpenCV
[OJ] intersection of two arrays (set, hash mapping...)
Several methods of the minimum value in the maximum value of group query
Open Source | Wenxin Big Model Ernie Tiny Lightweight Technology, Accurate and Fast, full Open Effect
Top Devops tool chain inventory
Happy Lantern Festival, how many of these technical lantern riddles can you guess correctly?
经济学外文文献在哪查?
maya渔屋建模
What website can you find English literature on?
Missing number
zhvoice
LeedCode1480.一维数组的动态和
SQL query statement parameters are written successfully