首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ipcs的“文件”在哪里,为什么命名管道(mkfifo)不在ipc中列出?

ipcs的“文件”在哪里,为什么命名管道(mkfifo)不在ipc中列出?
EN

Unix & Linux用户
提问于 2013-04-22 10:31:35
回答 2查看 1.3K关注 0票数 2

我当时正在研究linux,偶然发现了这个ipcs命令。

从手册页:

代码语言:javascript
复制
ipcs - provide information on ipc facilities

ipc在手册页中没有解释,但它很可能代表进程间的通信。这从它所列出的信息的上下文中也是有意义的:共享内存段、消息队列和信号量数组。

我想知道,由于linux/unix中的所有内容都是一个“文件”,或者至少是一个类似文件的对象,那么ipcs中列出的元素中的“文件”在哪里呢?

为什么mkfifo创建的命名管道没有在ipcs中列出?据我所知,fifos是队列。mkfifo创建的命名管道与ipcmk创建的消息队列有何不同?

EN

回答 2

Unix & Linux用户

回答已采纳

发布于 2013-04-22 12:31:16

ipcs允许您看到称为"System“的进程间通信方法。系统V工控机目前普遍被忽视,但在过去,人们明显不喜欢。显然,在早期,不同的群体会实现他们所需要的,以及有人需要消息队列、共享内存和信号量。

这些IPC方法因不是很统一,不是“文件”而受到广泛的批评,这和你质疑的东西是一样的。

我无法解释为什么命名管道和消息队列没有集成,但我敢打赌它起源于相同的方式:一个组想要命名管道,所以他们就去做了。

票数 3
EN

Unix & Linux用户

发布于 2013-04-22 12:23:58

这里有几个问题:

  • ipcs中列出的元素中的文件在哪里?

那得看情况。队列在虚拟文件系统中可见。来自mq_overview(7):

代码语言:javascript
复制
   Mounting the message queue file system
       On  Linux,  message queues are created in a virtual file system.  (Other implementations may also provide such a feature, but
       the details are likely to differ.)  This file system can be mounted (by the superuser) using the following commands:

           # mkdir /dev/mqueue
           # mount -t mqueue none /dev/mqueue

共享内存(shm_overview(7))

代码语言:javascript
复制
   Accessing shared memory objects via the file system
       On Linux, shared memory objects are created in a (tmpfs) virtual file system, normally mounted under /dev/shm.  Since  kernel
       2.6.19,  Linux supports the use of access control lists (ACLs) to control the permissions of objects in the virtual file sys-
       tem.

信号量(sem_overview(7))

代码语言:javascript
复制
   Accessing named semaphores via the file system
       On Linux, named semaphores are created in a virtual file system, normally mounted under /dev/shm,  with  names  of  the  form
       sem.somename.  (This is the reason that semaphore names are limited to NAME_MAX-4 rather than NAME_MAX characters.)

       Since  Linux  2.6.19,  ACLs can be placed on files under this directory, to control object permissions on a per-user and per-
       group basis.
  • 为什么mkfifo创建的命名管道没有在ipcs中列出?

我不确定,所以我只给你我的意见,而不是回答。我的假设是,由于它们存在于实际的文件系统中,比如套接字,所以内核管理共享内存段和消息队列的方式并不相同。

  • mkfifo创建的命名管道与ipcmk创建的消息队列有何不同?

管道和消息队列的主要区别在于,管道只是两个进程之间的通信通道。它在字节级工作。你可以用你想要的方式来读和写,你必须设计通讯协议。它们是严格的FIFO:在另一个字节之前写入的字节总是在另一端读取。消息队列处理消息,而不是字节。通常情况下,它们不是那么严格的FIFO。这取决于实现,但它们可以支持消息之间的优先级机制。

在某种程度上,消息队列提供了更多的功能,但如果您愿意,可以使用消息队列实现FIFO,反之亦然。

票数 5
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/73260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档