Example of using named pipes in Linux Bash

前端 未结 4 543
一向
一向 2020-12-02 05:36

Can someone post a simple example of using named pipes in Bash in Linux?

4条回答
  •  感动是毒
    2020-12-02 06:31

    Terminal 1:

    $ mknod new_named_pipe p
    $ echo 123 > new_named_pipe
    
    • Terminal 1 created a named pipe.
    • It wrote data in it using echo.
    • It is blocked as there is no receiving end (as pipes both named and unnamed need receiving and writing ends to it)

    Terminal 2:

    $ cat new_named_pipe
    $ 123
    $ 
    
    • From Terminal 2, a receiving end for the data is added.
    • It read the data in it using cat.
    • Since both receiving and writing ends are there for the new_named_pipe it displays the information and blocking stops

    Named pipes are used everywhere in Linux, most of the char and block files we see during ls -l command are char and block pipes (All of these reside at /dev). These pipes can be blocking and non-blocking, and the main advantage is these provides the simplest way for IPC.

提交回复
热议问题