Transcript Yun Zhang

Chapter 3 Computer Software
---- Operating System
Yun Zhang
Chapter 3 Computer Software
Readings:
• 3.1 Software Structure
• 3.2 Device Management and
Configuration
• 3.3 Resource Sharing
• 3.4 File Systems
Assessments:
• Exercise 3
2
Yun Zhang
• 操作系统是最底层的系统软件,它是对硬件
系统功能的首次扩充,也是其它系统软件和
应用软件能够在计算机上运行的基础。
• 操作系统具有五个方面的功能:内存储器管
理、处理机管理、设备管理、文件管理和作
业管理。
• 目前大都配置的WINDOWS操作系统有:
Windows 98、 Windows 2000、 Windows
xp等
- 《OS》中文教材,概述
3
Yun Zhang
3.1 Software Structure
3.1.1 Layers of Software
 Layers and Process Management
 Software systems are composed of multiple layers
 One example: sign a credit card slip to pay for dinner at
a restaurant – “a meal”
 the meal was actually composed of several courses.
That is a layer of detail the waiter needs to keep track
of in order to know what dishes to bring, and in what
order. For instance the first course was salad.
4
Yun Zhang
The details of salad preparation were
handled by another layer, the kitchen
where do croutons actually come from?
Where do flour come from?
Where do wheat come from?
When you pay for your dinner, you are
paying (indirectly) about one thousandth of
a cent to that farmer for the wheat in your
croutons. And, you are paying several
thousand other people who contributed to
your meal in various ways.
5
Yun Zhang
Fortunately, you do not have to pay all
those people directly! You make one
payment for "a meal," and the details are
sorted out in the layers below.
By organizing the production process into
layers that are relatively independent, the
entire system can be kept manageable,
and great efficiencies can be achieved. In
computer science, the principles
underlying these benefits are called
6
encapsulation and abstraction.
Yun Zhang
Encapsulation and Abstraction (封装与抽
象)
Encapsulation means that each layer needs
only a limited amount of knowledge to do its
job, and none of the other layers has access
to that information. The farmer does not know
what the wheat will be used for. The bakery
does not know how the wheat was harvested.
7
Yun Zhang
In the software world, encapsulation means that
your word processing program does not need to
know how to control disk drives in order to be
able to open and save files; there are layers of
software below it that handle those details.
if a layer were fully encapsulated it would be
unable to communicate with the layers above
and below. In order for there to be some
exchange of information, but not too much, the
designer of a layer specifies an abstraction that
the layer promises to support. (为上下层提供信
息接口)
8
Yun Zhang
The bakery supports an abstraction
called a "crouton order," whereby a
customer can submit an order for X
pounds of croutons and the bakery will
respond by producing the croutons and
delivering them. The details of how
crouton is produced are hidden from the
customer.
in computer science terminology(术语)
we say the information is encapsulated
9
Yun Zhang
abstraction
even if a customer knew that there were
two ovens(烤箱) to produce the croutons,
they could not specify(指定) which oven
they wanted to be used to produce their
order, because there is no place on the
order form to indicate that. In computer
science terms, we say that the crouton
ordering abstraction does not support
oven choice.
10
Yun Zhang
The existence of well-defined abstractions
at each layer means that one
implementation can be replaced by
another with no effect on the layers above
and below.
On your computer, it is possible to have
multiple implementations of a software
component and switch from one to another.
11
Yun Zhang
• For example, your Web browser calls on a
helper program when it needs to play a
sound file or video clip. There are several
programs that can perform this function.
All you have to do is tell your browser
which player to use. This isolation of
functionality means that if a new, improved
player becomes available, you can switch
to that one; you do not have to get a
completely new browser.
12
Yun Zhang
Layers of Software
User-Written Scripts or Macros
User Interface
Application
Run-time Library
Application Program Interface
Operating System
Kernel
Device Drivers
BIOS
(Hardware)
Table 1 Layers of software
• Hardware ,is the lowest level of the computer: the
physical components from which it is constructed.
Details have discussed in unit 2.
13
Yun Zhang
• The BIOS( Basic Input/Output System), is the
most fundamental level of software. It deals directly
with the signals that control each hardware
component. Much of its work is performed when
the computer is first turned on.
• Device drivers are the helper programs the
operating system uses to communicate with a
specific model of device. The advantage : the
operating system vendor does not have to be
responsible for supporting every device ever
invented, or that might be invented in the future.
14
Yun Zhang
• Device drivers example: The device driver
for a hard drive knows how many tracks are
on the drive and what commands to send to
the drive to move the arm to a specific track
and then read or write data.
– The device manufacturer supplies the driver,
and as long as the driver follows the
established conventions for communicating with
the operating system, the device should be
usable.
15
Yun Zhang
• The kernel is the heart of the operating system
and performs the functions that are most crucial(至
关紧要) for keeping everything running. It manages
memory, decides which task to run next, and
handles the various types of interrupts(中断) that
can occur. The kernel must stay resident in RAM
at all times, and because of its special nature, it
must run without some of the protection
mechanisms that guard against faulty instructions
or illegal memory accesses. Therefore, it is kept as
small as possible.
16
Yun Zhang
• The remaining layer of the operating
system is much larger than the kernel.
It implements all the other functions the
operating system is expected to perform.
Example: file system - managing the
folders and files on a disk.
It communicates with the kernel when it
needs to perform basic actions, such as
initiating a data transfer operation to a
peripheral.
17
Yun Zhang
API
• The application program interface (API),
is the layer where user programs
(applications) communicate with the
operating system. (API call )
18
Yun Zhang
API
• Example: suppose a Web browser application decides it
needs more memory in order to display a large image file.
The OS is responsible for keeping track of which
programs are using which chunks of memory at any
given time. This information is encapsulated within the
OS; the application does not know anything about how
the information is organized. It does not have to. The OS
defines an abstraction for managing memory (API call).
All the application developer has to know is which API
call to use to ask for more. If a new version of the OS
comes along that uses a different way to keep track of
memory, the application program will continue to work
just fine as long as the API call stays the same.
19
Yun Zhang
• Run-time libraries are collections of software
routines that application programs rely on.
• Example: you write an application in the C
language to open a file and read some data from it,
you will use two built-in functions called fopen and
fscanf. These functions are fetched from a library
of I/O routines called stdio that can be used by any
C program. They will make the appropriate API
calls to get the OS to do what you need. The nice
thing about the stdio abstraction is that your
program is not dependent on a specific set of API
calls, so you can run it on any machine that has a C
compiler and an implementation of the C runtime
library.
20
Yun Zhang
• The application layer is where you will find the
routines that do the actual work the application was
created for.
• The user interface layer is responsible for
communication between the application and the
user. It is typically a GUI (graphical user interface)
composed of buttons and pull-down menus.
• Scripts or macros are routines that many
applications allow users to create from the
application's set of built-in commands. Scripts and
macros allow users to automate sequences of
actions they perform frequently.
21
Yun Zhang
• The computer industry today relies on
specialists in each of the levels listed above.
Some people make their living writing BIOS
software, while others concentrate on
improving GUI technology. But, the greatest
number of programmers is found at the
application level, because people want to use
computers for so many different tasks.
22
Yun Zhang
3.1 Software Structure
3.1.2 The BIOS: Life at the Bottom
The Role of the BIOS
the lowest level of software on the machine
it initializes the hardware when the computer is
first turned on
it loads the operating system
it provides basic support for devices such as the
keyboard, mouse, and serial ports
it is only visible when you first power on the
computer, before the operating system takes
control
23
Yun Zhang
The BIOS resides in a ROM chip on the
motherboard. During the power-on sequence,
the processor automatically starts executing
instructions from the ROM. Since ROM is
slower than RAM, the BIOS on most systems
immediately copies itself from ROM into RAM.
Then it tells the processor to fetch all further
instructions from the RAM version.
24
Yun Zhang
Another special type of memory used by the
BIOS is CMOS memory. A small amount of
CMOS memory, often as little as 64 bytes, is
included on the motherboard to store BIOS
parameter settings that control the operation
of the hardware, and it uses very little power.
• If you purchase faster DRAM chips for your main memory,
you can change the BIOS settings to tell the memory bus
controller to take advantage of the higher DRAM speed.
25
Yun Zhang
POST
 When power is applied to the system and the BIOS
begins to execute, the BIOS initiates the POST
(Power-On Self Test) sequence
 First, it enables the video card (you will see the
screen flash) and displays some basic information
like the type of video card installed, the name of
the BIOS manufacturer, and the BIOS version
number
 It then determines the amount of DRAM installed in
the system, and it may perform a memory test.
26
Yun Zhang
POST
 Then, after determining what expansion cards
and adapters(适配器) are present, the BIOS
initializes those cards and adapters.
 At the conclusion of the POST sequence, the
BIOS displays system configuration information,
such as the type of processor installed, cache
memory information, the types of each of the
disk drives it found, the addresses of any serial
and parallel ports, and a list of other expansion
cards it detected.
27
Yun Zhang
After POST, BIOS is to load the OS. the BIOS
has to know just enough about disk drives to
be able to read in one chunk of data, called
the Master Boot Record, or MBR. By
convention, this is the first sector of the first
track of the disk. The MBR program then
loads in the OS and starts it running.
On a system with multiple disk drives, the
BIOS follows a search order to find an
operating system to load.
28
Yun Zhang
Changing BIOS Settings
– To change BIOS settings, you must enter the
BIOS setup program during the boot
sequence, by pressing a specified key or key
combination, such as F2 or ALT+CTRL+ESC
or Del.
29
Yun Zhang
3.1 Software Structure
3.1.3 Process(进程) Control
 One job of the OS is to keep track of all the
processes that are currently trying to execute,
assuring that each gets a chance to execute
reasonably often.
 A process is an instance of a running program. It
includes a set of memory pages, a set of open
file descriptors (if the process does any I/O), a
process ID, and several other things.
30
Yun Zhang
 Each process can be in one of several states:
running, runnable, or blocked. Only one
process per CPU can actually be running at a
time, although any number can be runnable
 The kernel maintains a list of every process in
the system. And maintains a queue (also called
the run queue), or waiting list of runnable
processes .
 Using the Windows NT/2000/XP Task Manager,
you can examine processes that are running,
the number of threads a process has, system
performance, and page faults.
31
Yun Zhang
3.2 Device Management and
Configuration
– Another one of the operating system's
functions is to manage the various I/O devices
installed on the computer. Control of the
hardware at this level requires interaction
between the kernel, the device drivers, and
the BIOS.
32
Yun Zhang
3.2.1 Interrupt Handling
 One of the important jobs of the kernel is to
handle interrupts.
 An interrupt is a signal to the processor that
some event has occurred that requires
immediate attention.
 The kernel figures out what caused the interrupt
and makes an appropriate response. It must act
very quickly. In order to avoid losing information
when the next interrupt arrives, it must handle
each interrupt in less than a thousandth of a
second.
33
Yun Zhang
IRQ
Interrupt Priority and Nested Interrupts Traps
and Faults
A trap is an event similar to an interrupt, except
that instead of being triggered(触发) by an
external signal, traps are triggered by the
execution of processor instructions. An example
is a division-by-zero operation.
A third type of event you should know about is
called a fault. A fault occurs when the hardware
is asked to do something it cannot do, such as
access a nonexistent memory location.
34
Yun Zhang
3.2.2 Hardware Attributes
 Installing Drivers
– Each device must have a corresponding driver in the
operating system. Each operating system specifies an
interface that a device driver must utilize.
– This means that for any particular device, it must have a
corresponding driver for the operating system where it is
intended to be used in order to be functional.
– Drivers are supplied either with the operating system's
distribution files, or individually from the manufacturer of
the hardware device.
35
Yun Zhang
Changing a Driver's Configuration
– A driver is designed to operate in a particular
fashion, but it may also include a number of
operations to customize its functions for a
particular user or system environment.
– Features to be modified include those that match
some particular hardware or system requirement
(such as the transfer speed of a modem, how
much data to buffer, what protocols should be
used, etc.), and those that are user-oriented
(screen's resolution分辨率, wallpaper, a lefthanded mouse, etc.).
36
Yun Zhang
3.2.3 Lab 3-B: Using the
Windows Interface
• How to access some of the Windows
device management capabilities
• “My Computer” - Properties
• 3.2.4 Lab 3-D: Installing and
uninstalling software
37
Yun Zhang
3.3 Resource Sharing
• the OS’s mechanism for resource sharing.
• The computer system not only shares
many of its internal resources, such as the
processor, but also its external resources,
such as the hard disk drive.
38
Yun Zhang
3.3.1 Virtual Memory
Managing Memory
• Some of main memory is reserved for the
operating system, but most of it is available for
user programs.
• Each of user’s programs (running a Web
browser, an editor, and a computer game etc.)
needs a certain amount of memory, but none of
them needs access to all the memory. The
kernel allocates some memory to each program
and keeps track of what program is using what.
39
Yun Zhang
• Modern operating systems such as Linux and
Windows provide virtual memory, to increase
program flexibility.
• In older operating systems like MS-DOS worked,
all programs ran in the same real address space,
since there was no virtual address space
– you (or the compiler) must calculate the address for
every instruction and every piece of data.
– suppose everyone else writes their programs the same
way, so you cannot run two programs that occupy the
same memory addresses at the same time since as soon
as you load the second one, it will overwrite the first.
40
Yun Zhang
• This scheme allows the computer to load multiple
programs in memory at once, in whatever portion
of memory is available at the time.
• it is simple to implement and does not require any
changes to the hardware.
• the memory allocated to the program must be
contiguous(连续的)
• Suppose the user is running a half a dozen small
programs at the same time. After some of these
programs have exited, programs 1, 3, and 6 are left
running. Now the user wants to run a big
application, but unfortunately, there may now be
nowhere to put it, even though the total number of
noncontiguous free blocks of memory may be more
than adequate.
41
Yun Zhang
• the size of a running program is limited to the
amount of physical memory installed on the
machine, minus whatever the operating system
has reserved for itself.
• But, large programs do not normally use all their
memory at once. A program with a large address
space may only need to access a few thousand
instructions and a few thousand bytes of data at
a time. It would be more efficient to allocate only
a little bit of RAM at a time to such a program and
to keep the rest of its address space somewhere
else, such as on disk. This is what virtual memory
allows us to do.
42
Yun Zhang
Virtual Memory
In a virtual memory system, every program
runs in its own private address space.
There is no need for any relocation when the
program is loaded into memory.
A virtual address space can be larger or
smaller than the processor's physical memory.
virtual memory requires hardware support.
43
Yun Zhang
3.3.2 File and Printer Sharing
• Files and printers are resources of the computer
that are shared in a networking environment,
allowing many users to access one drive, file, or
printer remotely.
• Files may be shared between applications or need
to be kept private
• the operating system defines a set of permissions
for a file or directory, also called Access Control
Lists (ACLs),
• Read access , Write access , Execute access
44
Yun Zhang
3.4 File Systems
• A file system is an abstraction for
organizing data on mass storage media
such as hard drives, floppy disks, and
optical disks. The file systems are
managed by the operating system of a
computer.
45
Yun Zhang
46
Yun Zhang
Drives
• Folders are housed in the computer drive.
• One way to access the drives is by
double-clicking on the icon named "My
Computer" on your Desktop. you will see
that each drive is labeled by an icon that
indicates the type of medium the drive
uses. Clicking a drive's icon will take you
to the root directory of that drive.
47
Yun Zhang
Shortcuts
• A shortcut is an alternate way to reach a file. Microsoft's
term for a symbolic link, stored as a file with extension
".lnk".
• A shortcut does not actually hold any data. It has a
shortcut property that specifies the path to the file where
the data can be found. This file is called the target of the
shortcut. A shortcut only refers to its target; it is not a
copy of the target.
• To create a shortcut:
• right-click the icon for the file or folder that is to be the
target
• select Create Shortcut from the pop-up menu).
• Note that you cannot create a shortcut to another
shortcut.
48
Yun Zhang
.txt
Plain text file
.doc
Microsoft Word document
.htm
HTML (Hypertext Markup Language) document
.xls
Microsoft Excel spreadsheet
.gif
GIF image (Graphic Interchange Format)
.jpg
JPEG image (Joint Photographic Experts Group)
.wav
Sound file
.exe
Executable file (binary machine code)
.com
MS-DOS executable ("command" file)
.drv
Driver (for a peripheral device)
.bat
Batch (script) file for the DOS command interpreter
49
Yun Zhang
3.4.2 File Allocation Table (FAT) and NT File
System
• Clusters and File Allocation Tables
Disks are divided into tracks and
sectors.
50
Yun Zhang
• Sectors hold a fixed number of bytes, typically
512 bytes. One or more sectors are allocated to
store a file. If the file contains only a line or two of
text, it will fit into a fraction of one sector. In that
case, the remainder of the sector is left unused.
• Because sectors are small, modern computer
systems group them into clusters and read or
write an entire cluster at a time.
• A cluster is the smallest amount of space any file
can occupy on a disk. A cluster contains 4, 8, 16,
32, or 64 adjacent sectors (the number must be a
power of 2).
51
Yun Zhang
• For each cluster that is part of a file, the
FAT entry gives the number of the next
cluster for that file. In this way, the clusters
that make up a file are chained together,
so if you know the address in the FAT of
the first cluster of a file, you can find all the
others by following the chain. The FAT
entry for the last cluster in the chain
contains a special marker to indicate that it
is the end of the chain.
52
Yun Zhang
• FAT16
the FAT used 16 bits (two bytes) per entry, which
allowed for a total of 216 or 65,536 clusters.
512 (29) bytes per sector * 64 (26) sectors per
cluster * 216 clusters in a FAT 16 partition = 231
bytes = 2GB
• FAT32
Windows 9x/2000/XP support a FAT32 file system.
32 bits (4 bytes) are used per entry, but the first 4
bits are reserved. smaller clusters can be used
instead of larger FAT16 clusters. This leads to
more efficient space allocation on the FAT32 drive
53
Yun Zhang
• NT File System
In NTFS, the cluster size is variable
depending on the size of the logical drives.
The cluster size is automatically
determined by the NTFS Format utility,
thereby, providing a level of flexibility. This
flexibility is not available in FAT16 or
FAT32. These features enable more
efficient allocation of disk space.
54
Yun Zhang
NTFS versus FAT
NTFS
Operating
System
Max Volume
Size*
Files per
Volume*
Max File Size*
•Windows XP
•Windows 2000
•Windows NT
FAT32
•Windows XP
•Windows 2000
•Windows 98
•Windows ME
•Windows 95
OEM Service
Release 2 (OSR2)
FAT16
•All versions of
Microsoft
Windows
•DOS
2 TB
32 GB
2 GB
~ 4 billion
~ 4 million
~ 64,000
2 TB
4 GB
2 GB
55
Yun Zhang
Exercise 3
• Question 1. Preemptive Multitasking
• In this section you will use a Timestamp program and a
graphical interface to examine how preemptive
processing works.
• Before executing the program, answer the following
questions in the context of an operating system:
• a. What is a process?
• b. What does a process include?
• c. Name the possible states that a process can be in.
• d. What is a thread?
• e. Why are threads useful?
56
Yun Zhang
Exercise 3
• Question 2. Virtual Memory
• In this section, you will use a program
demonstrating how virtual memory is used.
• a. How does virtual memory work using a
page table?
• b. What is the primary purpose of virtual
memory?
• c. List three advantages of using virtual
memory when executing a program.
57
Yun Zhang
Exercise 3
• Question 3. Troubleshooting
• Below are various problem scenarios. Select the most
likely cause(s) for the problem from the Causes list.
• Causes
A. Component not plugged in
B. Application software error
C. Operating system error
D. Low RAM
E. Slow processor
F. CMOS battery failure
G. Motherboard failure
H. Hard disk failure
I. BIOS ROM failure
J. Appropriate component driver not installed properly
58
Yun Zhang
Exercise 3
• Problems
a. Program not responding
Causes:
• b. Screen froze after successfully booting
Causes:
• c. Programs running slowly
Causes:
• d. Peripheral device not working (mouse,
keyboard, printer)
Causes:
59
Yun Zhang
Exercise 3
• e. All necessary computer system components
are plugged in, but the system does not boot
Causes:
• f. The computer is being booted, and an error
message indicates that the hard drive cannot be
found.
Causes:
• g. If low memory is a cause of the system
running slowly, what can you do as a user to
speed up the system?
60
Yun Zhang
Exercise 3
• Question 4. File Directories
• In this question, you are given a zip file, which
contains some folders and files. You will unzip
the given file, manipulate the files and folders,
zip the resulting file structure and submit it,
along with answers to the questions in this
exercise.
• First, download and save SSD2 File System.zip
onto your Desktop. Then unzip the file.
61
Yun Zhang
Exercise 3
• a. What is the absolute path of the file
named test.txt in SSD2 File System folder?
• b. How many parent directories does
test.txt have?
• c. Create a shortcut of test.txt and place it
in the same directory. Rename the
shortcut “MyTest”. Copy and paste a
screenshot showing the file property of
MyTest.
62
Yun Zhang
Exercise 3
• d. Examine the file property of test.txt. Explain
why the values for Size and Size on disk are
different. What is the term for the difference
between the two sizes?
• e. Opening MyTest or test.txt both result in the
display of the file. Explain the difference
between MyTest and test.txt.
• f. What are the different file extensions in folder
Temp1?
• g. List the most recently modified item in SSD2
File System folder.
63
Yun Zhang