C語言在open() FIFO文件的時候卡住了


須要注意的是,open打開FIFO文件的時候,open函數裏的flag參數 O——NONBLOCK:函數


置位:  若是「只寫」方式打開文件,寫進程會阻塞直到有一個讀進程來讀這個FIFO管道。就是說:沒有進程來讀文件,則寫進程會阻塞在open語句。
因此要read和write兩個程序一塊兒運行才能順利運行spa


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. 
進程

相關文章
相關標籤/搜索