fifo 中文man頁面
NAME
fifo - 先進先出的特殊文件, 又名管道
描述 (DESCRIPTION)
一個 FIFO 特殊 文件 (又名 管道) 同 管道線 相似, 但是 它是 作為 文件 系統 的一部分 訪問的. 可以 有 多個 進程 打開它 以供 讀寫. 當 進程 通過 FIFO 交換 數據的時候, 內核 在內部 傳送 所有 數據 而 不會 把它 寫入 文件 系統, 也就是說 FIFO 特殊 文件 在 文件 系統 中 沒有 任何 內容, 文件 系統 項 只是 作為 進程 可以 用文件 系統 中的 一個 名字 來 訪問 管道 的 一個 參照點.
內核 會 為 至少 有 一個 進程 打開 了的 FIFO 特殊 文件 維護 并且 也只 維護 一個管道 對象. 在 數據 傳給 FIFO 之前, FIFO 的 兩端 (讀 和 寫) 必須 同時 打開. 一般 來說 打開 FIFO 會 阻塞 直至 另一端 也 打開.
一個 進程 可以 以 非阻塞 模式 打開 一個 FIFO. 這種 情況下, 即使 寫端 沒有 打開, 打開 讀端 還是 會 成功, 但是, 如果 讀端 沒有 打開, 打開 寫端 會 失敗, 并且 得到一個 ENXIO (設備 或 地址 不存在).
在 Linux 下, 不管 是 阻塞 還是 非阻塞 模式, 打開 一個 FIFO 用作 讀 和 寫 都會成功. POSIX 關于 這種 情況 沒有 定義. 這個 可以 用來 在 讀端 沒有 打開 的 情況下 打開 寫端. 一個 進程 在 同時 用 FIFO 的 兩端 來 和 自己 通信 的 時候 要 特別注意 以防 死鎖.
注意 (NOTES)
當 一個 進程 企圖 向 讀端 沒有 打開 的 FIFO 寫 數據 的 時候, 進程 會 收到 一個 SIGPIPE 信號. FIFO 特殊 文件 可以 用 mkfifo(3) 來 創建 并且 ls -l 會 給它 一個 特殊 的 標記.
參見 (SEE ALSO)
mkfifo(3), mkfifo(1), pipe(2), socketpair(2), open(2), signal(2), sigaction(2)
#p#
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.
The kernel maintains exactly one pipe object for each FIFO special file that is opened by at least one process. The FIFO must be opened on both ends (reading and writing) before data can be passed. Normally, opening the FIFO blocks until the other end is opened also.
A process can open a FIFO in non-blocking mode. In this case, opening for read only will succeed even if noone has opened on the write side yet; opening for write only will fail with ENXIO (no such device or address) unless the other end has already been opened.
Under Linux, opening a FIFO for read and write will succeed both in blocking and non-blocking mode. POSIX leaves this behaviour undefined. This can be used to open a FIFO for writing while there are no readers available. A process that uses both ends of the connection in order to communicate with itself should be very careful to avoid deadlocks.
NOTES
When a process tries to write to a FIFO that is not opened for read on the other side, the process is sent a SIGPIPE signal.
FIFO special files can be created by mkfifo(3), and are specially indicated in ls -l.
SEE ALSO
mkfifo(3), mkfifo(1), pipe(2), socketpair(2), open(2), signal(2), sigaction(2)

















