OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Using Named Pipes

To demonstrate how the named pipe works, we will need two terminal windows (or alter- nately, two virtual consoles). In the first terminal, we enter a simple command and redi- rect its output to the named pipe:



[me@linuxbox ~]$ ls -l > pipe1

[me@linuxbox ~]$ ls -l > pipe1


After we press the Enter key, the command will appear to hang. This is because there is nothing receiving data from the other end of the pipe yet. When this occurs, it is said that the pipe is blocked. This condition will clear once we attach a process to the other end and it begins to read input from the pipe. Using the second terminal window, we enter this command:



[me@linuxbox ~]$ cat < pipe1

[me@linuxbox ~]$ cat < pipe1


and the directory listing produced from the first terminal window appears in the second terminal as the output from the cat command. The ls command in the first terminal successfully completes once it is no longer blocked.


Top OS Cloud Computing at OnWorks: