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