Page 445 - DCAP103_Principle of operating system
P. 445
Principles of Operating Systems
Notes Absolute path names are often long and inconvenient. For this reason, Linux allows
users and processes to designate the directory in which they are currently working as the
working directory. Path names can also be specified relative to the working directory. A
path name specified relative to the working directory is a relative path. For example, if
/usr/ast/books/mos3 is the working directory, then the shell command cp chap-10 backup-10
has exactly the same effect as the longer command cp /usr/ast/books/mos3/chap-10 /
usr/ast/books/mos3/backup-10. It frequently occurs that a user needs to refer to a file that
belongs to another user, or at least is located elsewhere in the file tree. For example, if two
users are sharing a file, it will be located in a directory belonging to one of them, so the other
will have to use an absolute path name to refer to it (or change the working directory). If this
is long enough, it may become irritating to have to keep typing it. Linux provides a solution to
this problem by allowing users to make a new directory entry that points to an existing file. Such
an entry is called a link. Consider this situation with an example shown in Figure 14.24. Fred
and Lisa are working together on a project, and each one needs frequent access to the other’s
files. If Fred has /usr/fred as his working directory, he can refer to the file x in Lisa’s directory as
/usr/lisa/x. Alternatively, Fred can create a new entry in his directory as shown in Figure 14.24,
after which he can use x to mean /usr/lisa/x.
In the example just discussed, we suggested that before linking, the only way for Fred to refer
to Lisa’s file x was using its absolute path. Actually, this is not really true. When a directory
is created, two entries and .., are automatically made in it. The former refers to the working
directory itself. The latter refers to the directory’s parent, that is, the directory in which it itself
is listed. Thus from /usr/fred, another path to Lisa’s file x is ../lisa/x. In addition to regular files,
Linux also supports character special files and block special files. Character special files are used
to model serial I/O devices such as keyboards and printers. Opening and reading from /dev/tty
reads from the keyboard; opening and writing to /dev/lp writes to the printer.
Figure 14.24: (a) Before Linking and (b) After Linking
/ /
bin bin
dev dev
etc etc
lib lib
tmp tmp
usr usr
Fred Lisa Fred Lisa
a X a X
b b Link
Y Y
c c
Z x Z
(a) (b)
Block special files, often with names like /dev/hd1, can be used to read and write raw disk
partitions without regard to the file system. Thus a seek to byte k followed by a read will begin
438 LOVELY PROFESSIONAL UNIVERSITY