📄 homework #1 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/hw1-sol.html -->
<HTML><HEAD><TITLE>CSE 120 (Fall 2004) -- Homework #1 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 (Fall 2004) -- Homework #1 Solution</H2><FONT color=blue
size=+1><B>Out: 9/28</B></FONT><BR><FONT color=red size=+1><B>In:
10/5</B></FONT>
<OL>
<P>
<LI>Chapter 1: 11
<P>1.11 Consider the various definitions of operating system. Consider whether
the operating sytem should include applications such as web browsers and mail
programs. Argue both pro and con positions, and support your answers. <I>
<P>PRO: provide a more convenient interface to end-user application
<P>CON: software complexity </I>
<P></P>
<LI>Chapter 2: 3, 5, 6, 8
<P>2.3 What are the differences between a trap and an interrupt? What is the
use of each function? <I>
<P>interrupt - async event triggered by hardware devices to info cpu to deal
with. trap - sync event tiggered by program itself to ask for OS service. </I>
<P>2.5 Which of the following instructions should be priviledged? <BR>a. Set
value of timer<BR>b. Read the Clock<BR>c. Clear Memory<BR>d. Turn off
interrupts<BR>e. Switch from user to monitor mode<BR>
<P><I>
<P>a. Set value of timer - priviledged otherwise the user program can play w/
it and the OS never gains control<BR>b. Read the Clock - not priviledged
because user program can't do anything harmful<BR>c. Clear Memory -
priviledged because user program shouldn't be able to clear arbitrary
memory<BR>d. Turn off interrupts - priviledged, reason is same as a<BR>e.
Switch from user to monitor mode - priviledged, otherwise the kernel is
useless<BR></I>
<P>2.6 Some computer systems do not provide a privileged mode of operation in
hardware. Is it possible to construct a secure operating system for these
comptuers? Give arguments both that it is and that it is not possible. <I>
<P>Secure OS = the user program can't crash the OS. <BR>Secure OS != the OS is
never infected by virus.
<P>POSSIBLE: it is possible by building a virtual machine on top of this
machine and export another pseudo instruction set to the user program. That is
we emulate a dual mode cpu and check every pseudo instructions. Or we can
limit all programs to be written and compiled by certain program language
(e.g. Java/MESA), and let compiler and loader do all the checking of
priviledged access.
<P>IMPOSSIBLE: the tradeoff of the above method is performance penalty,
checking every instruction can hurt the performance drasmatically.
<P>*Note: single user OS still needs this protection to make it secure,
because it can still crash the OS without it (DOS). </I>
<P>2.8 Protecting the operating system is crucial to ensureing that the
computer system opeartes correctly. Provision of this protection is the reason
for dual mode opeartion, memory protection, and the timer. To allow maximum
flexibility, however, you should also place minimla constraints on the use.
The following is a list of instructions that are normally protected. What is
the minimal set of instructions that must be protected? <BR>a. Change to user
mode <BR>b. Change to monitor mode <BR>c. Read from monitor memory <BR>d.
Write into monitor memory <BR>e. Fetch an instruction from monitor memory
<BR>f. Turn on timer interrupt <BR>g. Turn off timer interrupt <I>
<P>a. Change to user mode - no, since this action does no harm <BR>b. Change
to monitor mode - yes <BR>c. Read from monitor memory - yes, otherwise you can
peek other users' sensitive data. <BR>d. Write into monitor memory - yes,
otherwise you can change the kernel arbitrarily. <BR>e. Fetch an instruction
from monitor memory - no, even if you can fetch the instruction, you won't be
able to execute because of OS protection. <BR>f. Turn on timer interrupt - no,
the timer interrupt is almost always on so this action has no effect. (it
matters if you consider lock/semaphor issues, you get credit if you state
that) <BR>g. Turn off timer interrupt - yes, otherwise the OS can never gain
control actively. </I>
<P></P>
<LI>Chapter 3: 9
<P>3.9 Why does Java provide the ability to call from a Java program native
methods that are written in, say, C or C++? Provide an example where a native
method is useful. <I>
<P>basic - if a Java program requests for system services, the JVM needs to
call the OS interface, which are written by native code. native methods brige
the two. <BR>functionality - you can execute code that can't be implemented by
Java, like device drivers <BR>reusability - you don't have to re-implement
code <BR>performance - some native code are faster than the equivalent Java
code.
<P></I>
<P></P>
<LI>The Java runtime provides a set of standard system libraries for use by
programs. To what extent are these libraries similar to the system calls of an
operating system, and to what extent are they different? <I>
<P>The Java runtime provides an interface for invoking operations in the Java
virtual machine. These operations run within the JVM, have privileged access
to state in the JVM, and are not protected by Java language safety features.
<P>They are similar to system calls in that the JVM is similar to the OS, the
Java runtime operations execute within the JVM as system call code executes
within the OS, and the Java runtime operations perform privileged operations
as do system calls.
<P>They differ from system calls in that the Java runtime still executes
within the same process and address space as Java programs, it executes at
user level, and it cannot do machine-privileged operations as an OS can -- it
still must call into the OS to do truly privileged tasks. </I>
<P></P>
<LI>[Crowley] Suppose the hardware interval timer only counts down to zero
before signalling an interupt. How could an OS use the interval timer to keep
track of the time of day? <I>
<P>the OS reads the time from Real Time Clock (RTC) when it boots. the timer
expires every 100 millisecond, so the OS can keep track of the time by
increment .1 second when handling the timer interrrupt. the time-of-the-day is
generated by adding up the interval got from Timer and the boot time. </I>
<P></P>
<LI>[Tanenbaum] One reason GUIs were initially slow to be adopted was the cost
of the hardware needed to support them. How much video RAM, in bytes, is
needed to support a 25 line X 80 row character monochrome text screen? How
much for a 1024 X 768 24-bit color bitmap? What was the cost of this RAM at
1980 prices ($5/KB)? How much is it now (say, $0.25/MB)? <I><PRE>mono screen uses bitmapped font table, font is indexed by 1 byte long index.
RAM of mono screen = 25 * 80 * 1 = 2K Bytes
RAM of color screen = 1024 * 767 * 24 bits * 1/8 (byte/bit) = 2.3 MB
Cost in 1980 is 2.3 * 5 * 1024 = 1.1 K $
Cost in 2004 is 2.3 * 0.25 = 0.58 $
</PRE></I>
<P></P>
<LI>[Deitel] Using your Unix machine logged in with a normal user account
instead of root is an example of the principle of least privilege. Relate this
principle to the concepts of user mode, kernel mode, and privileged
instructions. <I>
<P>User mode is analogous to logging in as a normal user, and kernel mode and
privileged instructions are analogous to logging in as root.
<P>Logging in as root allows you to perform tasks that require special,
resricted privileges. These tasks should only be performed by users who know
what they are doing and have the privileges to do it (have root access).
Similarly, being able to execute privileged instructions allows you to perform
special tasks (manipulate hardware). These instructions should only be
executed by code that knows what it is doing (code written by OS developers)
and that has the privileges to do it (executing in kernel mode in the OS).
<P>You only want to login as root to do administrative tasks that require root
privileges so that you minimize mistakes and accidents. Similarly, you want to
minimize the amount of code you execute in kernel mode to minimize the chance
that bugs in the code will cause the system to crash, cause data corruption,
create security holes, etc., </I></P></LI></OL><PRE></PRE>
<HR>
<ADDRESS><A href="mailto:voelker@cs.ucsd.edu">voelker@cs.ucsd.edu</A>
</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -