Linux系統程式設計之FIFO通訊

2021-10-21 10:29:04 字數 953 閱讀 4970

fifo: (有名管道) 應用於非血緣關係程序間(不能反覆讀取)

例如://04_fifo_w.c

#include

#include

#include

#include

#include

#include

int main(

) //當前目錄有乙個myfifo檔案

//開啟fifo檔案『

printf(

"begin write...\n");

int fd=open(ar**[1],o_wronly)

; prinhtf(

"end write...\n");

//寫char buf[256]

; int num=1;

while(1)

//關閉描述符

close(fd)

;return 0;

}

//04_fifo_r.c

#include

#include\

#include

#include

#include

#include

int main(

) printf(

"begin read...\n");

int fd=open(ar**[1],o_rdonly)

; prinhtf(

"end read...\n");

char buf[256]

; while(1)

} close(fd)

;return 0;

}

輸出:先執行寫,輸出顯示「begin write…」 執行完open函式後程序被阻塞了,一直到另外乙個程序執行讀,程序才會被釋放

注意:

Linux系統程式設計 管道和FIFO

ls wc l 為執行上述命令,shell建立了兩個程序來分別執行ls和wc。通過管道連線兩個程序。管道是單向的,允許資料從乙個程序流向另乙個程序。管道是乙個位元組流意味著在使用管道時不存在訊息或訊息邊界。從管道中讀取資料的程序可以讀取任意大小的資料塊,而不管寫入程序寫入管道的資料塊大小。通過管道的...

Linux系統程式設計 fifo命名管道

fifo也被稱為命名管道。未命名的管道只能在兩個相關的程序之間使用,而且這兩個程序還有乙個共同的建立了他們的祖先程序,但是fifo,不相關的程序也能交換資料。fifo是一種檔案型別,fifo的建立有兩種方式。1.直接用命令建立 mkfifo 2.利用函式建立 int mkfifo const cha...

Linux系統程式設計之程序

程序狀態 4 5種 就緒 初始化 執行,掛起 等待 停止 pbc成員 1 程序id 2 程序狀態 3 程序切換需要儲存和恢復的cpu暫存器 4 描述虛擬位址空間資訊 5 描述控制終端的資訊 6 當前工作目錄 7 umask掩碼 8 檔案描述符 9 訊號相關的資訊 10 使用者和使用者組id 11 會...