4. Anonymous Pipes and Named Pipes Now, if (Fedora web server)
4. Anonymous Pipes and Named Pipes Now, if we do: $ rm a $ ls -il b 32555 -rw-r–r–1 queen queen 0 Aug 6 19:26 b $ We see that even though we deleted the original file , the inode still exists. But now, the only link to it is the file named /home/queen/example/b. Therefore a file in UNIX has no name; instead, it has one or more link(s) in one or more directories. Directories themselves are also stored in inodes. Their link count coincides with the number of sub-directories within them. This is due to the fact that there are at least two links per directory: the directory itself (represented by the entry .) and its parent directory (represented by ..). So a directory with two sub-directories will have at least four links: ., .. and links for each sub-directory. Typical examples of files which are not linked (i.e.: have no name) are network connections. You will never see the file corresponding to your connection to the Mandriva Linux web site [http://www.mandrivalinux.com] in your file tree, no matter which directory you look in. Similarly, when you use a pipe in the shell, the inode corresponding to the pipe exists, but it is not linked. Temporary files are another example of inodes without names. You create a temporary file, open it, and then remove it. The file exists while it’s open, but nobody else can open it (as there is no name to open it). This way, if the application crashes, the temporary file is removed automatically. 4. Anonymous Pipes and Named Pipes Let’s get back to the example of pipes, as it is quite interesting and is also a good illustration of the links notion. When you use a pipe in a command line, the shell creates the pipe for you and operates so that the command before the pipe writes to it, while the command after the pipe reads from it. All pipes, whether they be anonymous (like the ones used by the shells) or named (see below) act like FIFOs (First In, First Out). We’ve already seen examples of how to use pipes in the shell, but let’s take another look for the sake of our demonstration: $ ls -d /proc/[0-9] | head -5 /proc/1/ /proc/2/ /proc/3/ /proc/4/ /proc/5/