UNIX System Administration Handbook - Evi Nemeth [49]
Device files are characterized by two numbers, called the major and minor device numbers. The major device number tells the kernel which driver the file refers to, and the minor device number tells the driver which physical unit to address. For example, major device number 6 on a Linux system indicates the parallel port driver. The first parallel port (/dev/lp0) would have major device number 6 and minor device number 0.
Some device drivers use the minor device number in a nonstandard way. For example, tape drivers often use the minor device number to select a density at which to write tapes and to determine whether the tape should be rewound when the device file is closed. On some systems, the “terminal driver” (which actually handles all serial devices) uses minor device numbers to distinguish modems used as outgoing dialers from modems used on dial-in ports.
You can create device files with mknod and remove them with rm. Most systems provide a shell script called MAKEDEV (usually found in /dev) that creates the appropriate sets of device files for common devices. Be sure to read the MAKEDEV script to see what it will do before blindly invoking it.
UNIX domain sockets
Sockets are connections between processes that allow them to communicate in a hygienic manner. UNIX provides several different kinds of sockets, most of which involve the use of a network. UNIX domain sockets are local to a particular host and are referenced through a filesystem object rather than a network port. The POSIX standard refers to them as “local domain sockets.”
Although socket files are visible to other processes as directory entries, they cannot be read from or written to by processes not involved in the connection. Some standard facilities that use UNIX domain sockets are the printing system, the X Windows system, and syslog.
See Chapter 11 for more information about syslog.
UNIX domain sockets are created with the socket() system call and can be removed with the rm command or the unlink() system call when the socket no longer has any users.
Named pipes
Like UNIX domain sockets, named pipes allow communication between two unrelated processes running on the same host. They’re also known as “FIFO files” (FIFO is short for the phrase “first in, first out”). You can create named pipes with mknod and remove them with rm.
As with UNIX domain sockets, real-world instances of named pipes are few and far between. They rarely, if ever, require administrative intervention.
Symbolic links
A symbolic or “soft” link points to a file by name. When the kernel comes upon a symbolic link in the course of looking up a pathname, it redirects its attention to the pathname stored as the contents of the link. The difference between hard links and symbolic links is that a hard link is a direct reference, whereas a symbolic link is a reference by name; symbolic links are distinct from the files they point to.
You create symbolic links with ln -s and remove them with rm. Since they can contain arbitrary paths, they can refer to files on other filesystems or to nonexistent files. Several symbolic links can also form a loop.
A symbolic link can contain either an absolute or a relative path. For example,
# ln -s ../../ufs /usr/include/bsd/sys/ufs
links /usr/include/bsd/sys/ufs to /usr/include/ufs with a relative path. The entire /usr/include directory could be moved somewhere else without causing the symbolic link to stop working.
Beware of using “..” in pathnames that travel through symbolic links, since symbolic links can’t be followed in reverse. “..” always refers to a directory’s true parent.