fopen 管道

场景:fopen 打开定名管道阻塞

fopen 打开命名管道阻塞

使用fopen以写的方式打开命名管道,若没有别的进程/线程以读的方式打开命名管道,该函数将一直阻塞。

 写道
O_NONBLOCK
When opening a FIFO with O_RDONLY or O_WRONLY set: If O_NONBLOCK is set:
An open() for reading only will return without delay. An open() for writing only will return an error if no process currently has the file open for reading.
If O_NONBLOCK is clear:
An open() for reading only will block the calling thread until a thread opens the file for writing. An open() for writing only will block the calling thread until a thread opens the file for reading.

 

参考 

  • http://pubs.opengroup.org/onlinepubs/007908799/xsh/open.html
  • http://stackoverflow.com/questions/580013/how-do-i-perform-a-non-blocking-fopen-on-a-named-pipe-mkfifo
  • Linux命名管道FIFO的读写规则