We can use mkfifo
or mknod
command to create a named pipe. A pipe is a structure which one end can send message and the other can consume it.
To create a named pipe, we can use mkfifo
or mknod
:
$ mkfifo pipe1
# we can see the file type is "named pipe" using `file` command
$ file pipe1
pipe1: fifo (named pipe)
$ ls -al pipe1
prw-r--r-- 1 userx userx 0 Dec 29 20:35 pipe1
# or we can use mknod, "p" indicate this "node" is a pipe
$ mknod pipe2 p
$ file pipe2
pipe2: fifo (named pipe)
Now let's send/consume messages with this pipe. Open a terminal window:
$ tail -f pipe1
Open another terminal window, write a message to this pipe:
$ echo "hello" >> pipe1
Now in the first window you can see the "hello" printed out:
$ tail -f pipe1
hello
Because it is a pipe and message has been consumed, if we check the file size, you can see it is still 0:
$ ls -al pipe1
prw-r--r-- 1 userx userx 0 Dec 29 20:35 pipe1
Top comments (1)
Here is a quick video demo on how to do that as well: