2、進程間通信-FIFO(有名管道)

1、具有親緣關係的進程,使用FIFO通信

父進程向管道寫入數據,子進程從管道中讀出數據

code:

結果:

fathe with pid of 2750 write data :Hello pipe
child with pid of 2751 read data :Hello pipe
PS:注意,在使用有名管道時,一定要使用兩個進程分別打開其讀端和寫端,open操作

 

 

2、非親緣關係進程,使用有名通道(FIFO)通信

codes:

發送數據進程:

讀取數據進程:

 

結果:

發送:
root@ubuntu:/code/chap8 # ./run5_input
Process 2016:open it
the file descriptor is 3
write |Hello this a test about pipe| with 31 bytes
Process 2016:finished
讀取:
root@ubuntu:/code/chap8 # ./run5_output
Process 2017: open fifo
the file descriptor is 3
the data read is |Hello this a test about pipe| with 31 bytes
Process 2017:finished

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章