当我在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.
Run Code Online (Sandbox Code Playgroud)
我想这就是你需要的.
试想一下它是一个缓冲区.它必须通过不同的过程打开读取和写入.正在阅读的过程将被阻止,直到写入过程没有写入.当写入过程完成写入时,关闭文件,这是读取过程开始清空缓冲区的绿灯.它是一个FIFO,因此写入的第一行将是第一行读取.然后写作过程可以再次打开它们再次开始.
您可以使用创建FIFO mkfifo.看看man mkfifo.