?? homework #4 solution.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0059)http://www.cse.ucsd.edu/classes/fa04/cse120/hw/hw4-sol.html -->
<HTML><HEAD><TITLE>CSE 120 (Fall 2004) -- Homework #4 Solution</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2627" name=GENERATOR></HEAD>
<BODY>
<H2>CSE 120 -- Homework #4 Solution</H2><FONT color=blue size=+1><B>Out:
11/23</B></FONT><BR><FONT color=red size=+1><B>Due: 12/2</B></FONT>
<OL>
<LI>Chapter 11: 11.5, 11.9, 11.12
<P>[4pt] 11.5 What are the advantages and disadvantages of recording the
name of the program that creates a file with the file's attributes (as is done
in the Macintosh operating system)?
<P><FONT color=#0000ff>Advantages: A file tagged with a program name
indirectly points to the default program to open/execute the file. First, this
makes the file dependency on application programs very explicit. This
visibility is useful (more than that in having extensions in DOS and Windows)
to the user in determining the application associated with the file.
Furthermore, it removes all ambiguity when determining which program to use to
open a file. </FONT>
<P><FONT color=#0000ff>Disadvantages: Some files are used by multiple
applications, so the one-to-one mapping with the embedded filename becomes
much less useful. Furthermore, the explicit association could break over time
if the application is moved or removed. </FONT>
<P>11.9 Give an example of an application in which data in a file should
be accessed in the following order:
<P>a. [2pt] Sequentially<BR><FONT color=#0000ff>A movie player that plays a
movie file sequentially.<BR></FONT><BR>b. [2pt] Randomly<BR><FONT
color=#0000ff>A movie player that allows user to start playing movie at random
locations of the file.<BR></FONT>
<P>11.12 Consider a system that supports 5000 users. Suppose that you
want to allow 4990 of these users to be able to access one file.
<P>a. [2pt] How would you specify this protection scheme in Unix?<BR><FONT
color=#0000ff>Add 4990 users into a group, set the file's group permission,
and deny anyone else.</FONT>
<P>b. [2pt] Could you suggest another protection scheme that can be used more
effectively for this purpose than the scheme provided by Unix?<BR><FONT
color=#0000ff>Put the 10 users in the deny list of the file like NTFS. </FONT>
<P></P>
<LI>Chapter 12: 12.9, 12.10
<P>12.9 [2pt] How do caches help improve performance? Why do systems not
use more or larger caches if they are so useful?
<P><FONT color=#0000ff>There are two reasons why increasing file cache size
eventually stops being useful. First, programs exhibit locality with
diminishing returns. Eventually, increasing the cache size only negligibly
improves cache hit rate. Second, the file buffer cache competes with virtual
memory for physical memory resources. Using more memory for the file cache
reduces the memory used for virtual memory. Reducing virtual memory increases
page faults, increasing I/Os (operatings which the file cache was trying to
decrease). </FONT>
<P>12.10 [2pt] In what situations would using memory as a RAM disk be
more useful than using it as a disk cache?
<P><FONT color=#0000ff>A RAM disk is a file system that resides completely in
memory. No data is stored persistently on disk. It is similar to a file buffer
cache, except that it is organized just like a file system and used regardless
of access locality to files stored in the RAM disk. Using a RAM disk is useful
for managing files that can be easily regenerated. For example, compilers
generate many intermediate files and these files can be usefully and safely
stored in a RAM disk. The final program files can be saved to a normal disk.
Many operating systems mount /tmp as a RAM disk for these reasons. </FONT>
<P></P>
<LI>[Crowley] A file system is the data structure that holds files and
directories.
<UL>
<LI>[2pt] Is it possible to have two file systems on a single physical disk
drive? Why or why not?
<LI>[2pt] Is it possible to have a file system that spans two physical disk
drives? Why or why not?
<LI>[2pt] Is it possible to have a file that is not in a file system? Why or
why not?
<LI>[2pt] The mount operation allows you to graft the directory tree from
one file system onto the directory tree of another file system. Does this
mean that a file can span both file systems? Why or why not? </LI></UL>
<P><FONT color=#0000ff>a) Yes. A file system is just a logical abstraction of
the disk. So, it is possible to maintain two or more file systems on the same
disk as long as they are physically partitioned from each other. If you
dual-boot your computer from the same disk, you likely have a disk with both a
Windows and Linux file system on it. </FONT>
<P><FONT color=#0000ff>b) Yes. A file system can span multiple disks as long
as it is aware of the disks the files are scattered over. A file system
installed on a RAID device, for example, spans multiple disks. </FONT>
<P><FONT color=#0000ff>c) No. A file has no logical existence (just a stream
of bytes) without a data structure to access it. And this data structure is
the file system. So a file without a file system is meaningless. <!-- Yes. A file that is deleted while anotherprocess keeps it open is one example. You cannot find it in the filesystem by name, but the file still exists.--></FONT>
<P><FONT color=#0000ff>d) No. Mounting provides a method of traversing from
one file system to another through one joining node (directory) called the
mount point. These file systems span distinct logical disks. One single file
cannot reside simultaneously on multiple logical disks. Hence a single file
cannot span multiple file systems. </FONT>
<P></P>
<LI>[4pt] On a Unix file system, how many disk read operations are required to
read the first block of the file "/home/solaris/ieng9/cs120f/file"? Assume
that the master block is in memory, but nothing else. Also assume that all
directories are one block in size. </LI></OL>
<P> <FONT
color=#0000ff>12 reads.
<P> 0. Get the inode
location of / from the Master block (in
memory)<BR> 1. Read
the inode and get the location of the / directory
<BR> 2. Read / and
look for the entry of home. The entry gives the location of the inode of
home.<BR> 3-10.
repeat last two steps for home, solaris, ieng9,
cs120f<BR> 11. Read
the inode and get the location of the file
<BR> 12. Read first
block fo file</FONT> </P></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -