当前位置:网站首页>UNIX Environment Programming Chapter 15 15.5FIFO

UNIX Environment Programming Chapter 15 15.5FIFO

2022-08-09 10:28:00 Mary Soda Meatloaf

FIFOs are sometimes named pipes.Through FIFO, unrelated processes can also exchange data.

Creating a FIFO is similar to creating a file

#include int mkfifo(const char *path,mode_t mode);int mkfifoat(int fd,const char *path,mode_t mode);//successful return 0, error return -1
The specification of the

mode parameter is the same as that of the mode in the open function.

When opening a FIFO, the non-blocking flag has the following effects:

  • Under normal circumstances, the system open blocks until other processes open the FIFO for writing.Similarly, write-only open blocks until some other process opens it for reading.
  • If O_NONBLOCK is specified, read-only open returns immediately.However, if no process has a FIFO open for reading, write-only open will return -1 and set errno to ENXIO.

It is common to have multiple writing processes for a given FIFO, which means that atomic operations must be considered if data written by multiple processes is not expected to be interleaved.

FIFO serves two purposes:

  1. The shell command uses FIFO to transfer data from one pipe to another without creating intermediate temporary files.
  2. In a client-server application, the FIF acts as a rendezvous point, passing data between the client and server processes.

原网站

版权声明
本文为[Mary Soda Meatloaf]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091026200752.html