mic*_*con 8 filesystems pipe fifo
如果我创建一个命名管道,然后对其进行读/写,命名管道所在的文件系统是否受到影响?即数据是在文件系统上缓冲直到读取,还是仅驻留在内存中?
文件对象本身是在文件系统中创建的,但没有数据存储在文件系统中。从 mkpipe(3) 联机帮助页:
A FIFO special file is similar to a pipe, except that it is created in
a different way. Instead of being an anonymous communications channel,
a FIFO special file is entered into the file system by calling
mkfifo().
Run Code Online (Sandbox Code Playgroud)
大约唯一一次数据可能存储在磁盘上的时间是在休眠期间,当内存写入交换空间(包括缓冲区)时 - 但这是一个极端情况。
小智 5
不。写入命名管道不会修改文件系统(访问时间除外)。
这是一个演示:
$ mkdir test
$ mkdir test-ro
$ mkfifo test/fifo
$ mount --bind test test-ro
$ mount -o remount,ro test-ro
$ cat test/fifo & echo something >> test/fifo
something
Run Code Online (Sandbox Code Playgroud)
如您所见,即使 fifo 位于只读文件系统上,我们也能够对其进行写入。
命名管道不会在文件系统上存储任何管道数据。它们的数据缓冲在内存中,与文件系统缓冲区分开。