加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 通过文件进行进程间通信

发布时间:2020-12-14 00:52:16 所属栏目:Linux 来源:网络整理
导读:当我在 Linux中的某些任意位置回应文件时,即echo / tmp / file,一些正在运行的进程响应.这个IPC是通过文件管道吗? 这是否意味着正在运行的进程始终打开要读取的文件?但是,如何编写文件,因为文件流是由自己的进程锁定的? 解决方法 如果你想使用一个文件与
当我在 Linux中的某些任意位置回应文件时,即echo> / tmp / file,一些正在运行的进程响应.这个IPC是通过文件管道吗?

这是否意味着正在运行的进程始终打开要读取的文件?但是,如何编写文件,因为文件流是由自己的进程锁定的?

解决方法

如果你想使用一个文件与另一个进程通信,你应该看一下man fifo.

我在这里只报告第一行:

NAME
       fifo - first-in first-out special file,named pipe

DESCRIPTION
       A FIFO special file (a named pipe) is similar to a pipe,except that it
       is accessed as part of the file system.  It can be opened  by  multiple
       processes  for  reading or writing.  When processes are exchanging data
       via the FIFO,the kernel passes all data internally without writing  it
       to the file system.  Thus,the FIFO special file has no contents on the
       file system; the file system entry merely serves as a  reference  point
       so that processes can access the pipe using a name in the file system.

我想这就是你需要的.

试想一下它是一个缓冲区.它必须通过不同的过程打开读取和写入.正在阅读的过程将被阻止,直到写入过程没有写入.当写入过程完成写入时,关闭文件,这是读取过程开始清空缓冲区的绿灯.它是一个FIFO,因此写入的第一行将是第一行读取.然后写作过程可以再次打开它们再次开始.

您可以使用mkfifo创建FIFO.看看男人mkfifo.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读