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