Page 238 - DCAP103_Principle of operating system
P. 238

Unit 6: File Management



            the command cp mailbox mailbox.bak do exactly the same thing if the working directory is /usr/  Notes
            ast/. The relative form is often more convenient, but it does the same thing as the absolute form.
            Some programs need to access a specific file without regard to what the working directory
            is. In that case, they should always use absolute path names. For example, a spelling checker
            might need to read /user/lib/dictionary to do its work. It should use the full, absolute path
            name in this case because it does not know what the working directory will be when it is
            called. The absolute path name will always work, no matter what the working directory is of
            course, if the spelling checker needs a large number of files from /user/lib/, an alternative
            approach is for it to issue a system call to change its working directory to /user/lib/, and
            then use just dictionary as the first parameter to open. By explicitly changing the working
            directory, it knows for sure where it is in the directory tree, so it can then use relative paths.
            Each process has its own working directory, so when a process changes its working directory
            and later exits, no other processes are affected and no traces of the change are left behind in the
            file system. In this way it is always perfectly safe for a process to change its working directory
            whenever  that  is  convenient  on  the  other  hand,  if  a  library  procedure  changes  the  working
            directory and does not change back to where it was when it is finished, the rest of the program
            may not work since its assumption about where it is may now suddenly be invalid. For this
            reason,  library  procedures  rarely  change  the  working  directory,  and  when  they  must,  they
            always change it back again before returning.
            Most operating systems that support a hierarchical directory system have two special entries in
            every directory, “.” and “..”, generally pronounced “dot” and “dotdot.” Dot refers to the current
            directory; dotdot refers to its parent. To see how these are used, consider the UNIX file tree of
            Fig. 6.15 A certain process has /usr/ast/ as its working directory. It can use .. to go up the tree.
            For example, it can copy the file /usr/lib/dictionary to its own directory using the command:
            cp ../lib/dictionary.
                                   Figure 6.15: A UNIX Directory Tree








































                                             LOVELY PROFESSIONAL UNIVERSITY                                   231
   233   234   235   236   237   238   239   240   241   242   243