離弦之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的技術天空 閱讀(284) 評論(0)  編輯  收藏 所屬分類: Linux&C

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


          網站導航:
           
          主站蜘蛛池模板: 建阳市| 措美县| 房山区| 彭水| 兴海县| 彭阳县| 浠水县| 丹寨县| 汾阳市| 肥西县| 黎城县| 买车| 河曲县| 久治县| 从江县| 井研县| 崇明县| 靖边县| 蓝山县| 康平县| 丰宁| 渝中区| 江永县| 花莲县| 盐津县| 梅河口市| 车致| 靖安县| 宜州市| 双城市| 唐河县| 蓬安县| 大理市| 体育| 广平县| 务川| 红桥区| 静海县| 吐鲁番市| 凌源市| 育儿|