📄 unit 6-87%.htm
字号:
mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;color:black;
mso-font-kerning:0pt;mso-ansi-language:EN-US'><span style='mso-list:Ignore'>·<span
style='font:7.0pt "Times New Roman"'>
</span></span></span><![endif]><span lang=EN-US style='font-size:12.0pt;
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'><a
href="javascript:AssessmentByName('assm-exer-os-interaction');">Exercise 6</a> <o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;margin-left:36.1pt;text-align:left;text-indent:-18.0pt;mso-pagination:
widow-orphan;mso-list:l9 level1 lfo2;tab-stops:list 36.0pt'><![if !supportLists]><span
lang=EN-US style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Symbol;
mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;color:black;
mso-font-kerning:0pt;mso-ansi-language:EN-US'><span style='mso-list:Ignore'>·<span
style='font:7.0pt "Times New Roman"'>
</span></span></span><![endif]><span lang=EN-US style='font-size:12.0pt;
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'><a
href="javascript:AssessmentByName('assm-qz-pr-os-interaction');">Practical Quiz
4</a> <o:p></o:p></span></p>
<p class=MsoNormal align=left style='margin-top:12.0pt;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:10.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>© Copyright 1999-2005 iCarnegie, Inc. All rights reserved.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan;mso-outline-level:2'><b><span
lang=EN-US style='font-size:18.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>6.1 Time-Sharing<o:p></o:p></span></b></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;margin-left:36.1pt;text-align:left;text-indent:-18.0pt;mso-pagination:
widow-orphan;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><![if !supportLists]><span
lang=EN-US style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Symbol;
mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;color:black;
mso-font-kerning:0pt;mso-ansi-language:EN-US'><span style='mso-list:Ignore'>·<span
style='font:7.0pt "Times New Roman"'>
</span></span></span><![endif]><span lang=EN-US style='font-size:12.0pt;
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'><a
href="javascript:ContentByName('pg-why-time-sharing');">6.1.1 Why Time-Share a
PC?</a> <o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;margin-left:36.1pt;text-align:left;text-indent:-18.0pt;mso-pagination:
widow-orphan;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><![if !supportLists]><span
lang=EN-US style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Symbol;
mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;color:black;
mso-font-kerning:0pt;mso-ansi-language:EN-US'><span style='mso-list:Ignore'>·<span
style='font:7.0pt "Times New Roman"'>
</span></span></span><![endif]><span lang=EN-US style='font-size:12.0pt;
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'><a
href="javascript:ContentByName('pg-system-calls');">6.1.2 System Calls</a> <o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;margin-left:36.1pt;text-align:left;text-indent:-18.0pt;mso-pagination:
widow-orphan;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><![if !supportLists]><span
lang=EN-US style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Symbol;
mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;color:black;
mso-font-kerning:0pt;mso-ansi-language:EN-US'><span style='mso-list:Ignore'>·<span
style='font:7.0pt "Times New Roman"'>
</span></span></span><![endif]><span lang=EN-US style='font-size:12.0pt;
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'><a
href="javascript:ContentByName('pg-context-switching');">6.1.3 Context
Switching</a> <o:p></o:p></span></p>
<p class=MsoNormal align=left style='margin-top:12.0pt;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:10.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>© Copyright 1999-2005 iCarnegie, Inc. All rights reserved.<o:p></o:p></span></p>
<b><span lang=EN-US style='font-size:18.0pt;font-family:SimSun;mso-bidi-font-family:
SimSun;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA'><br clear=all style='page-break-before:always'>
</span></b>
<h2><span lang=EN-US style='font-family:"Times New Roman";color:black;
mso-ansi-language:EN-US'>6.1.1 Why Time-Share a PC?<o:p></o:p></span></h2>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>Time-sharing occurs when more than one program executes at the same
time. Unless there is more than one processor, programs do not actually execute
simultaneously, but a rapid switching of the processor from one program to the
next gives the impression of simultaneous execution.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>Time-sharing was originally developed so that multiple users could
"share" a single computer. In addition to making users happy,
time-sharing is a way to better utilize expensive computers: interactive
computer usage often involves a lot of "think time." While one user
is thinking, the time-shared computer can service other users.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>It may seem odd to implement time-sharing on a personal computer that
can be dedicated to a single user. In fact, personal computers were invented in
part to avoid the sluggish response that was typical of time-shared computers.
Now, however, users want the same sorts of services from their personal
computers as they received from time-shared computers, including the ability to
share files, to send and receive email with notification when mail arrives, to
have automatic file backup without stopping other work, etc. Besides, even when
the user is only running one application program, the personal computer often
has many processes running to provide services.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>There are a few tools that show the processes that are running on your
computer. Process Viewer, a program that comes with Visual C++ 6.0 and Windows
Task Manager are a couple of such tools. As I type into Dreamweaver (a Web page
editor) on a laptop running Windows 2000, Windows Task Manager lists the
following processes:<o:p></o:p></span></p>
<p class=MsoNormal align=center style='text-align:center;mso-pagination:widow-orphan'><span
lang=EN-US style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" alt="Process viewer"
style='width:317.25pt;height:351pt'>
<v:imagedata src="Unit%206_files/image001.gif" o:href="http://www.icarnegie.com/content/SSD/SSD6/2.0/normal/pg-os-interaction/pg-time-sharing/pg-why-time-sharing/processes.gif"/>
</v:shape><![endif]--><![if !vml]><img border=0 width=423 height=468
src="Unit%206_files/image001.gif" alt="Process viewer" v:shapes="_x0000_i1025"><![endif]><o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>Included in the list of processes are programs I did not even know were
running, such as a hardware vendor-supplied personal information manager and
mdm.exe a Microsoft process debugging system. You might want to look at
processes running on your computer.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='margin-top:12.0pt;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:10.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>© Copyright 1999-2005 iCarnegie, Inc. All rights reserved.<o:p></o:p></span></p>
<b><span lang=EN-US style='font-size:18.0pt;font-family:SimSun;mso-bidi-font-family:
SimSun;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA'><br clear=all style='page-break-before:always'>
</span></b>
<h2><span lang=EN-US style='font-family:"Times New Roman";color:black;
mso-ansi-language:EN-US'>6.1.2 System Calls<o:p></o:p></span></h2>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>Modern operating systems can run multiple programs concurrently. A
running program is generally called a process. It is convenient to call a
running program a "process" rather than a "program," because
you might run two copies of the same program, in which case you would have two
processes, but only one program. It is also possible for multiple processes to
communicate and cooperate. Sometimes, a single program creates multiple
processes to accomplish its goals.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>In general, a process has an address space to store its data (including
a stack for local variables and subroutine return addresses), a set of
processor registers (which are active while the process is running but saved
outside the CPU while another process is running), and a set of operating
system resources such as network connections and open file handles. Included in
the registers is the program counter, which gives the location of the next
instruction to be executed.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>The operating system must provide memory and must schedule processor
time for each process. In addition, the operating system must prevent bugs or
even malicious behavior in one process from affecting other programs. Keeping
programs and their influence separate is sometimes referred to as <i>protection</i>.
Protection involves at least the following fundamentals:<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;margin-left:36.1pt;text-align:left;text-indent:-18.0pt;mso-pagination:
widow-orphan;mso-list:l6 level1 lfo4;tab-stops:list 36.0pt'><![if !supportLists]><span
lang=EN-US style='font-size:12.0pt;mso-fareast-font-family:"Times New Roman";
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'><span
style='mso-list:Ignore'>1.<span style='font:7.0pt "Times New Roman"'>
</span></span></span><![endif]><span lang=EN-US style='font-size:12.0pt;
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'>Each executing
program has its own memory. It is not possible for one process to directly
access the memory of another process. <o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;margin-left:36.1pt;text-align:left;text-indent:-18.0pt;mso-pagination:
widow-orphan;mso-list:l6 level1 lfo4;tab-stops:list 36.0pt'><![if !supportLists]><span
lang=EN-US style='font-size:12.0pt;mso-fareast-font-family:"Times New Roman";
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'><span
style='mso-list:Ignore'>2.<span style='font:7.0pt "Times New Roman"'>
</span></span></span><![endif]><span lang=EN-US style='font-size:12.0pt;
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'>No process is allowed
to "steal" the processor. Even if a program tries to execute an
infinite loop, a timer eventually interrupts the processor and transfers
control to some other processes. <o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;margin-left:36.1pt;text-align:left;text-indent:-18.0pt;mso-pagination:
widow-orphan;mso-list:l6 level1 lfo4;tab-stops:list 36.0pt'><![if !supportLists]><span
lang=EN-US style='font-size:12.0pt;mso-fareast-font-family:"Times New Roman";
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'><span
style='mso-list:Ignore'>3.<span style='font:7.0pt "Times New Roman"'>
</span></span></span><![endif]><span lang=EN-US style='font-size:12.0pt;
color:black;mso-font-kerning:0pt;mso-ansi-language:EN-US'>Processes are not
allowed free access to input/output devices such as the screen, the disk, and
the network. <o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>We have discussed virtual memory, and you should be able to see how
virtual memory can provide the memory protection required for fundamental
number 1 above. To implement fundamental number 2, processor hardware
automatically transfers control from user programs to the operating system at a
programmable time interval. The operating system can then give control to
another process. To implement fundamental number 3 (protected access to
hardware devices), processors are designed so that applications cannot execute
instructions that manipulate devices, or at least not directly. To get access
to devices, the application must make a request to the operating system. These
requests use a special hardware-supported instruction called a <i>trap</i>.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>A trap is a very clever invention that enables application programs to
call operating system functions, but only in a very restricted way. To protect
the operating system, the calling program must <i>not</i> have access to
operating system memory, and the "called" function must <i>not</i> be
allowed to begin execution at any arbitrary location in the operating system.
The operating system cannot even use the caller's stack because the caller's
stack pointer may not point to valid memory. The trap instruction allows the
operating system to guard against any error or even attack from a process.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>Traps are instructions that invoke operating system functions. Before
executing a trap instruction, the caller loads parameters into registers (the
exact interface is determined by the designers of the operating system.) Then,
the trap instruction is executed. The trap transfers control to the operating
system by loading a special value into the program counter (sometimes this
value is loaded from a table indexed by a number provided by the calling process).
In addition, <i>the address space is changed to the operating system's address
space.</i> The operating system then checks the parameters carefully, and if
the calling program is allowed to perform the requested operation, the
operating system performs it. The system then causes the application to resume
executing in its own address space, and usually a result value is returned in a
register for examination by the calling process.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
style='font-size:12.0pt;color:black;mso-font-kerning:0pt;mso-ansi-language:
EN-US'>Why all this mechanism just to call a function? The important thing is
that this mechanism allows the operating system to regulate application
processes. The application process cannot call just any subroutine in the
operating system (or worse, jump into the middle of some arbitrary sequence of
instructions). The application's trap instruction will only transfer control
(set the program counter) to addresses stored in a table <i>by the operating
system.</i> The operating system resides in a separate address space, so there
is no other way the application can affect the operating system. Finally, the
operating system can (and must) carefully check all parameters passed to it by
the application. For example, if the application requests a write to a disk
location, the operating system will check that the location exists and that the
application is allowed to perform the write according to file system
permissions. In short, the application can make requests, but the operating
system is in complete control and decides what operations to perform on behalf
of the application.<o:p></o:p></span></p>
<p class=MsoNormal align=left style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
auto;text-align:left;mso-pagination:widow-orphan'><span lang=EN-US
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -