C语言在open() FIFO文件的时候卡住了


需要注意的是,open打开FIFO文件的时候,open函数里的flag参数 O——NONBLOCK:


置位:  如果“只写”方式打开文件,写进程会阻塞直到有一个读进程来读这个FIFO管道。就是说:没有进程来读文件,则写进程会阻塞在open语句。
所以要read和write两个程序一起运行才能顺利运行


O_NONBLOCK
When opening a FIFO with O_RDONLY or O_WRONLY set:

* If O_NONBLOCK is set, an open() for reading-only shall return without delay. An open() for writing-only shall return an error if no
process currently has the file open for reading.

* If O_NONBLOCK is clear, an open() for reading-only shall block the calling thread until a thread opens the file for writing. An open()
for writing-only shall block the calling thread until a thread opens the file for reading. 

posted @ 2013-09-02 11:47  leechanx  阅读(1960)  评论(0编辑  收藏  举报