精品丰满熟女一区二区三区_五月天亚洲欧美综合网_亚洲青青青在线观看_国产一区二区精选

  • <menu id="29e66"></menu>

    <bdo id="29e66"><mark id="29e66"><legend id="29e66"></legend></mark></bdo>

  • <pre id="29e66"><tt id="29e66"><rt id="29e66"></rt></tt></pre>

      <label id="29e66"></label><address id="29e66"><mark id="29e66"><strike id="29e66"></strike></mark></address>
      學習啦 > 學習電腦 > 操作系統(tǒng) > Linux教程 > Linux怎么創(chuàng)建FIFO

      Linux怎么創(chuàng)建FIFO

      時間: 春健736 分享

      Linux怎么創(chuàng)建FIFO

        管道只能用于在同一祖父進程創(chuàng)建的進程間進行通信,F(xiàn)IFO(先進先出)類似于管道,也只能單向傳遞數(shù)據(jù)流。不過每個FIFO都有一個路徑名與之關(guān)聯(lián),這就允許無親緣關(guān)系的進程間可以實現(xiàn)通信。FIFO也稱有名管道。那么Linux怎么創(chuàng)建FIFO?下面跟著學習啦小編一起去了解下吧。

        Linux怎么創(chuàng)建FIFO

        FIFO管道是一種文件類型,在Linux上創(chuàng)建FIFO非常容易,F(xiàn)IFO文件固有管道的特性,但和pipe管道有一定的區(qū)別

        FIFO和pipe的區(qū)別在于:

        FIFO在文件系統(tǒng)中有對應(yīng)的inode,可以通過ls命令查看。

        sh-3.2# ls -lhF 。/fifo_file

        100 prwxrwxrwx 1 root root 0 Jan 1 1970 。/fifo_file|

        sh-3.2#

        正因為它有一個名字,所以任何進程都可以訪問它,所以FIFO可用于任意兩個進程之間的通信。

        pipe沒有名字,在現(xiàn)有文件系統(tǒng)中無法查看到它的存在。

        它只能用于父子進程、兄弟進程等具有血緣關(guān)系的進程間通信。

        創(chuàng)建FIFO的方法如下:

        1. 調(diào)用umask系統(tǒng)調(diào)用來設(shè)定創(chuàng)建文件的權(quán)限,

        #include 《sys/types.h》

        #include 《sys/stat/h》

        mode_t umask(mode_t mask);

        2. 調(diào)用unlink系統(tǒng)調(diào)用先刪除已經(jīng)存在的fifo,

        #include 《unistd.h》

        int unlink(const char *pathname);

        3. 調(diào)用mkfifo庫函數(shù)去創(chuàng)建一個FIFO文件,

        #include 《sys/types.h》

        #include 《sys/stat.h》

        int mkfifo(const char *pathname, mode_t mode);

        或者可以通過調(diào)用mknod系統(tǒng)調(diào)用并且指定參數(shù)mode為S_IFIFO也可以創(chuàng)建一個FIFO文件,

        #include 《sys/types.h》

        #include 《sys/stat.h》

        #include 《fcntl.h》

        #include 《unistd.h》

        int mknod(const char *pathname, mode_t mode, dev_t dev);

        注意:

        1. 使用FIFO進行通信,每次傳輸?shù)臄?shù)據(jù)要限定在PIPE_BUF之內(nèi);

        2. 對于FIFO的訪問就像訪問正規(guī)文件(regular file)一樣,可以使用open/read/write/close等系統(tǒng)調(diào)用進行訪問。

        使用FIFO的應(yīng)用有:

        1. 單純的生產(chǎn)者/消費者問題,一個進程讀數(shù)據(jù),一個進程寫數(shù)據(jù);

        2. 實現(xiàn)client/server架構(gòu)的程序,客戶端和服務(wù)器端通過FIFO進行通信。

        上面就是Linux創(chuàng)建FIFO管道的方法介紹了,本文除了介紹了FIFO管道的創(chuàng)建外,還稍微介紹了下FIFO的使用及其注意事項,在使用的時候需特別注意。

      看過“ Linux怎么創(chuàng)建FIFO ”的人還看了:

      1.Linux下如何實現(xiàn)shell多線程編程

      2.Linux find命令常見用法

      3.關(guān)于Linux操作系統(tǒng)的相關(guān)知識介紹

      653098