4. Anonymous Pipes and Named Pipes One thing (Web site translator)

4. Anonymous Pipes and Named Pipes One thing that you will not notice in this example (because it happens too fast for one to see) is that writes on pipes are blocking. This means that when the ls command writes to the pipe, it is blocked until a process at the other end reads from the pipe. In order to visualize the effect, you can create named pipes, which unlike the pipes used by shells, have names (i.e.: they are linked, whereas shell pipes 2 are not). The command to create a named pipe is mkfifo: $ mkfifo a_pipe $ ls -il total 0 169 prw-rw-r–1 queen queen 0 Aug 6 19:37 a_pipe| # # You can see that the link counter is 1, and that the output shows # that the file is a pipe (’p'). # # You can also use ln here: # $ ln a_pipe the_same_pipe $ ls -il total 0 169 prw-rw-r–2 queen queen 0 Aug 6 19:37 a_pipe| 169 prw-rw-r–2 queen queen 0 Aug 6 19:37 the_same_pipe| $ ls -d /proc/[0-9] >a_pipe # # The process is blocked, as there is no reader at the other end. # Type Control Z to suspend the process… # [1]+ Stopped ls -F –show-control-chars –color=auto -d . /proc/[0-9] >a_pipe # # …Then put in into the background: # $ bg [1]+ ls -F –show-control-chars –color=auto -d /proc/[0-9] >a_pipe & # # now read from the pipe… # $ head -5

Leave a Reply