離弦之Ray

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            55 Posts :: 0 Stories :: 33 Comments :: 0 Trackbacks
          A FIFO is similar to a pipe. A FIFO is a one-way flow of data (First In First Out). FIFOs have a name, so unrelated processes can share the FIFO. FIFO is a named pipe.

          FIFO和PIPE基本差不多,但FIFO是命名的,一些沒有親緣關系的process能共享它。

          Normally, opening a FIFO for read or write, it blocks until another process opens it for write or read. Write and read必須一一對應。

          A read gets as much data as it requests or as much data as the FIFO has, whichever is less.

          A write to a FIFO is atomic, as long as the write does not exceed the capacity of the FIFO. The capacity is at least 4k.


          How to set flags.

          writefd = open (FIFO1, O_WRONLY|O_ONOBLOCK,0);

          但是pipe沒有open函數

          所以只能這樣設定

          flags= fcntl (fd, F_GETFL,0);

          flag|=O_NONBLOCK;

          fcntl =(fd,F_SETFL,flags);


          下面的表很重要,要看清下面的前提操作和當前操作,主要比較了Blocking和O_NONBLOCK條件下的區別

          Operation

          Existing opens of pipe or FIFO

          Blocking (default)

          O_NONBLOCK set

          Open FIFO for reading

          FIFO open for writing

          Returns OK

          Returns OK

          FIFO not open for writing

          Blocks until FIFO is opened for writing

          Returns OK

          Open FIFO for writing

          FIFO open for reading

          Returns OK

          Returns OK

          FIFO not open for reading

          Blocks until FIFO is opened for reading

          Returns an error of ENXIO

          Read empty pipe or FIFO

          Pipe or FIFO open for writing

          Blocked until there is data or the pipe or FIFO is closed for writing

          Return an error of EAGAIN

          Pipe or FIFO not open for writing

          Read returns 0 (EOF)

          Read return 0 (EOF)

          Write to pipe or FIFO

          Pipe or FIFO open for reading

          Return ok

          Return ok

          Pipe or FIFO is full

          Blocked until space is available, then write data

          Returns an error of EAGAIN

          Pipe or FIFO not open for reading

          SIGPIPE generated, write process terminated

          Returns an error of EPIPE



          posted on 2006-06-20 23:42 離弦之ray的技術天空 閱讀(279) 評論(0)  編輯  收藏 所屬分類: Linux&C

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 府谷县| 朝阳市| 正安县| 平谷区| 万源市| 景东| 岱山县| 于都县| 祁东县| 偃师市| 金乡县| 通城县| 娄烦县| 麦盖提县| 巴楚县| 丰都县| 临江市| 罗城| 舟山市| 合水县| 鄱阳县| 洱源县| 黑龙江省| 溧阳市| 沐川县| 克山县| 阳新县| 巴中市| 阿坝| 柳河县| 通化县| 荣昌县| 孟津县| 都昌县| 常宁市| 柳河县| 房产| 合水县| 保康县| 涞源县| 张家川|