环境:Vmware Workstation;CentOS-6.4-x86_64
说明:
创建有名管道,并在两个控制台窗口中使用管道进行通信。
步骤:
1、创建管道,并查看管道信息:
[negivup@negivup mycode]$ mkfifo fifo 这是创建管道的命令
[negivup@negivup mycode]$ ls -l
总用量 0
prw-rw-r--. 1 negivup negivup 0 9月 21 15:24 fifo p代表的是管道的意思
2、查看管道所在的目录:
[negivup@negivup mycode]$ pwd
/home/negivup/mycode
3、在第一个终端窗口中读取管道信息:
[negivup@negivup mycode]$ cat < fifo 此时会等待管道中传递数据并输出
4、打开第二个终端窗口,进入管道所在目录,并向管道中写入数据:[negivup@negivup mycode]$ cd /home/negivup/mycode
[negivup@negivup mycode]$ echo "hello fifo" > fifo
5、切换到第一个终端窗口查看信息:[negivup@negivup mycode]$ cat < fifo
hello fifo
会发现,管道中的信息已经存在了第一个终端窗口上,说明写入和读取管道没有问题。
PS:根据传智播客视频学习整理得出。