2013-11-28 44 views
0

为什么函数open()在Unix中对于FIFO是不对称的?为什么我们需要首先打开先进先出读取然后写入? 在linux/fs/fifo.c写:为什么FIFO文件在打开之前必须打开才能读取?

/* 
* O_RDONLY 
* POSIX.1 says that O_NONBLOCK means return with the FIFO 
* opened, even when there is no process writing the FIFO. 
*/ 

/******** 
* O_WRONLY 
* POSIX.1 says that O_NONBLOCK means return -1 with 
* errno=ENXIO when there is no process reading the FIFO. 
*/ 

为什么不能老是我们首先打开一个只写后读?

回答

0

我猜想原因是许多程序本来应该停留在读取端,并且为了写入而打开它,其目的是为了避免客户端关闭其写入结束时的SIGPIPE/IO错误。就内核而言,作家,除了它从不写入,所以实际上读取会看到阻塞读取。

例如:clockspeed.c

相关问题