Operating System Principles

Download Report

Transcript Operating System Principles

Operating System
Principles
Ku-Yaw Chang
[email protected]
Assistant Professor, Department of
Computer Science and Information Engineering
Da-Yeh University
Ku-Yaw Chang
Chapter 2 System Structures
1
Chapter 2 System Structures
An operating system can be viewed from
different vantage points

Services that the system provides
Programmers

Interface available to users and programmers
Users

Components and their connections
Operating system designer
Ku-Yaw Chang
Chapter 2 System Structures
2
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
3
2.1 Operating-System Services
Common services (1/2)

User interfaces
Command-line interface (CLI)

Batch interface
Graphical user interface (GUI)

Program execution
to load a program into memory and to run it.

I/O operations
user programs cannot execute I/O operations directly
Ku-Yaw Chang
Chapter 2 System Structures
4
2.1 Operating-System Services
Common services (1/2)

File-system manipulation
capability to read, write, create, and delete files

Communications
exchange of information between processes
Implemented via shared memory or message
passing

Error detection
ensure correct computing by detecting errors in the
CPU and memory hardware, in I/O devices, or in
user programs
Ku-Yaw Chang
Chapter 2 System Structures
5
Additional Functions
Not for helping the user, but rather for ensuring
efficient system operations

Resource allocation
allocate resources to multiple users or multiple jobs running
at the same time

Accounting
keep track of and record which users use how much and
what kinds of computer resources for account billing or for
accumulating usage statistics

Protection and security
ensure that all access to system resources is controlled
each user authenticate himself or herself to the system
Ku-Yaw Chang
Chapter 2 System Structures
6
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
7
User Operating-System Interface
Two approaches for users to interact with OS


Command-line interface (CLI) or command interpreter
Graphical user interface (GUI)
Ku-Yaw Chang
Chapter 2 System Structures
8
2.2.1 Command Interpreter
Command interpreter


Included in the OS kernel
Treated as a special program
Windows XP and UNIX
Also known as shells


Multiple command interpreters to choose from
On UNIX and Linux systems
 Bourne-Again shell
 Korn shell
Bourne shell
C shell

See what was my login shell?
saturn% echo $SHELL
/bin/csh
Ku-Yaw Chang
Chapter 2 System Structures
9
2.2.1 Command Interpreter
Main function

To get and execute the next user-specified command
Example : file manipulation

create, delete, list, print, copy, execute
Internal vs. external command

Internal
The command interpreter contains the code to execute the
command

External
Use the command to identify a file to be loaded into memory
and executed
Ku-Yaw Chang
Chapter 2 System Structures
10
2.2.2 Graphical User Interfaces
User-friendly desktop metaphor interface





A mouse-based window-and-menu system
Usually mouse, keyboard, and monitor
Icons represent files, programs, actions, etc
Various mouse buttons over objects in the interface
cause various actions (provide information, options,
execute function, open directory (known as a folder)
Invented at Xerox PARC
Ku-Yaw Chang
Chapter 2 System Structures
11
2.2.2 Graphical User Interfaces
Many systems now include both CLI and GUI
interfaces

Microsoft Windows is GUI with CLI “command” shell
command.com or cmd.exe


Apple Mac OS X as “Aqua” GUI interface with UNIX
kernel underneath and shells available
Solaris is CLI with optional GUI interfaces (Java
Desktop, KDE)
Ku-Yaw Chang
Chapter 2 System Structures
12
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
13
2.3 System Calls
The interface between a process and the OS


Assembly-language
Higher-level language
C, C++ and Perl
Mostly accessed by programs via a high-level
Application Program Interface (API) rather than
direct system call use



Win32 API for Windows
POSIX API for POSIX-based systems (including
virtually all versions of UNIX, Linux, and Mac OS X)
Java API for the Java virtual machine (JVM)
Ku-Yaw Chang
Chapter 2 System Structures
14
2.3 System Calls
Why use APIs rather than system calls?


Better program portability
Easy to work with
Ku-Yaw Chang
Chapter 2 System Structures
15
Depiction of XP Architecture
Ku-Yaw Chang
Chapter 2 System Structures
16
Different Types of I/O
Low-level I/O (system call)


_open, _close
_read, _write
Stream I/O


fopen, fclose
fread, fwrite
WIN32 API


CreateFile, CloseHandle
ReadFile, WriteFile
Ku-Yaw Chang
Chapter 2 System Structures
17
Example of Standard API
Consider the ReadFile() function in the Win32 API

a function for reading from a file
A description of the parameters passed to ReadFile()





HANDLE file—the file to be read
LPVOID buffer—a buffer where the data will be read into and written from
DWORD bytesToRead—the number of bytes to be read into the buffer
LPDWORD bytesRead—the number of bytes read during the last read
LPOVERLAPPED ovl—indicates if overlapped I/O is being used
Ku-Yaw Chang
Chapter 2 System Structures
18
2.3 System Calls
Even simple programs may make heavy use of
the operating system.

To read data from one file and to copy them to
another file
Requiring a sequence of system calls

Details are hidden from the programmer
Ku-Yaw Chang
Chapter 2 System Structures
19
System Call Sequence
Ku-Yaw Chang
Chapter 2 System Structures
20
System Call Implementation
Typically, a number associated with each system call

System-call interface maintains a table indexed according to
these numbers
The system call interface invokes intended system call in
OS kernel and returns status of the system call and any
return values
The caller need know nothing about how the system call
is implemented


Just needs to obey API and understand what OS will do as a
result call
Most details of OS interface hidden from programmer by API
Managed by run-time support library (set of functions built into
libraries included with compiler)
Ku-Yaw Chang
Chapter 2 System Structures
21
The Handling of open() System Call
Ku-Yaw Chang
Chapter 2 System Structures
22
Standard C Library Example
C program invoking printf() library call, which calls write()
system call
Ku-Yaw Chang
Chapter 2 System Structures
23
System Call Parameter Passing
Three general methods used to pass parameters to the
OS

Simplest: pass the parameters in registers
In some cases, may be more parameters than registers

Parameters stored in a block, or table, in memory, and address
of block passed as a parameter in a register
This approach taken by Linux and Solaris

Parameters placed, or pushed, onto the stack by the program
and popped off the stack by the operating system
Block and stack methods do not limit the number or
length of parameters being passed
Ku-Yaw Chang
Chapter 2 System Structures
24
Parameter Passing via Table
Ku-Yaw Chang
Chapter 2 System Structures
25
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
26
2.4 Types of System Calls
Five major categories





Process control
File management
Device management
Information maintenance
Communications
Ku-Yaw Chang
Chapter 2 System Structures
27
2.4.1 Process Control
A running program

Halt its execution
normally (end)
abnormally (abort)


A dump of memory
Load and execute another program
fork()
exec()
Ku-Yaw Chang
Chapter 2 System Structures
28
MS-DOS
At System Start-up
Ku-Yaw Chang
Running a Program
Chapter 2 System Structures
29
FreeBSD running multiple programs
Ku-Yaw Chang
Chapter 2 System Structures
30
2.4.5 Communication
Two common models

Message-passing
Messages can be exchanged either directly or indirectly
through a common mailbox
A connection must be established

open, connection, close
Useful for smaller amounts of data
Easier for intercomputer communication

Shared-memory
Create and gain access to regions of memory owned by
other processes
Maximum speed and convenience
Ku-Yaw Chang
Chapter 2 System Structures
31
2.4.5 Communication
Message Passing
Ku-Yaw Chang
Shared Memory
Chapter 2 System Structures
32
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
33
2.5 System Programs
System programs provide a convenient environment for
program development and execution






File management
Status information
File modification
Programming language support
Program loading and execution
Communication
System utilities or application programs

To solve common problems, or perform common operations
Web browsers and word processors
Games
Ku-Yaw Chang
Chapter 2 System Structures
34
2.5 System Programs
Command interpreter


The most important system program
Two approaches
The command interpreter contains the code to execute the
command.

Internal command
Implement most commands by system programs

Ku-Yaw Chang
External command
Chapter 2 System Structures
35
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
36
2.6.1 Design Goals
User goals

should be convenient to use, easy to learn, reliable,
safe, and fast
System goals

should be easy to design, implement, and maintain,
as well as flexible, reliable, error-free, and efficient
Ku-Yaw Chang
Chapter 2 System Structures
37
2.6.2 Mechanisms and Policies
General software engineering principles are
applicable to operating systems

Separation of policy from mechanism
For flexibility
Mechanisms


How to do something
A general mechanism
Policies


What will be done
Change across places or over time
Ku-Yaw Chang
Chapter 2 System Structures
38
2.6.2 Mechanisms and Policies
Microkernel-based

Take the separation of mechanism and policy to one
extreme
Windows / Apple Macintosh (Mac OS X)

Both mechanism and policy are encoded in the
system
Ku-Yaw Chang
Chapter 2 System Structures
39
2.6.3 Implementation
Traditionally written in assembly language,
operating systems can now be written in higherlevel languages such as C/C++

Linux and Windows XP are written mostly in C
Code written in a high-level language:





can be written faster
more compact
easier to understand and debug
easier to port (move to some other hardware)
Disadvantage
Reduced speed and increased storage requirements
Ku-Yaw Chang
Chapter 2 System Structures
40
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
41
2.7 Operating-System Structure
To partition the task (OS) into small components
(modules)

Not one monolithic system
Available approaches




Simple structure
Layered approach
Microkernels
Modules
Ku-Yaw Chang
Chapter 2 System Structures
42
2.7.1 Simple Structure
MS-DOS



written to provide the most functionality in the least
space
not divided into modules
Although having some structure, its interfaces and
levels of functionality are not well separated
Ku-Yaw Chang
Chapter 2 System Structures
43
MS-DOS Layer Structure
Ku-Yaw Chang
Chapter 2 System Structures
44
2.7.1 Simple Structure
UNIX (original)

consists of two separable parts
Kernel

everything below the system-call interface and above the
physical hardware
System programs
Ku-Yaw Chang
Chapter 2 System Structures
45
Unix System Structure
Ku-Yaw Chang
Chapter 2 System Structures
46
2.7.2 Layered Approach
OS is broken into a number of layers (or levels)



Each built on top of lower layers
The bottom layer (layer 0) is the hardware
The highest layer (layer N) is the user interface
With modularity, layers are selected such that
each uses functions (operations) and services of
only lower-level layers.



Simplify debugging and system verification
Difficult to define each layer
Less efficient – overhead
Ku-Yaw Chang
Chapter 2 System Structures
47
A Layered OS
Ku-Yaw Chang
Chapter 2 System Structures
48
An OS layer
Ku-Yaw Chang
Chapter 2 System Structures
49
OS/2 layer structure
Ku-Yaw Chang
Chapter 2 System Structures
50
Windows NT
First release


A highly layer-oriented organization
Low performance (compared to Windows 95)
NT 4.0

Move layers from user space to kernel space
Closely integration
Ku-Yaw Chang
Chapter 2 System Structures
51
2.7.3 Microkernels
Mach


Developed at Carnegie Mellon University in the mid1980s
Use the microkernel approach
Removing non-essential components from the kernel
Implement them as system- and user-level programs
A smaller kernel
Main function

Ku-Yaw Chang
To provide a communication facility
Chapter 2 System Structures
52
2.7.3 Microkernels
Benefits




easier to extend
easier to port
more security
more reliability
Examples




Tru64 UNIX – UNIX + Mach kernel
MacOS X – based on Mach kernel
QNX – a real-time OS
Windows NT ( a hybrid structure)
Ku-Yaw Chang
Chapter 2 System Structures
53
Windows NT client-server structure
Ku-Yaw Chang
Chapter 2 System Structures
54
2.7.4 Modules
Most modern operating systems implement
kernel modules




Uses object-oriented approach
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernel
Overall, similar to layers but with more flexible
Ku-Yaw Chang
Chapter 2 System Structures
55
Solaris Loadable Modules
Ku-Yaw Chang
Chapter 2 System Structures
56
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
57
2.8 Virtual Machines
A computer system is made up of layers

Hardware is the lowest
Virtual machines

take the layered approach to its logical conclusion
treat hardware and the operating system kernel as though
they were all hardware

provide an interface identical to the underlying bare
hardware
OS creates the illusion of multiple processes

each has on its own processor with its own (virtual)
memory
Ku-Yaw Chang
Chapter 2 System Structures
58
System Models
Non-virtual Machine
Ku-Yaw Chang
Virtual Machine
Chapter 2 System Structures
59
2.8.1 Implementation
Difficult to implement

To provide an exact duplicate of the underlying
machine
User mode
Monitor mode
Time – the major difference

I/O
Less time or more time

CPU
Multiprogrammed among many virtual machines
Ku-Yaw Chang
Chapter 2 System Structures
60
2.8.2 Benefits
Provide complete protection of system resources

Each virtual machine is isolated from all other virtual
machines.
Permits no direct sharing of resources
A perfect vehicle for operating-systems research
and development


System development is done on the virtual machine,
instead of on a physical machine and so does not
disrupt normal system operation
Solve system compatibility problems
Ku-Yaw Chang
Chapter 2 System Structures
61
2.8.3 Examples
2.8.3.1 VMware



a popular commercial application
abstract Intel 80X86 hardware
run several guest operating systems concurrently
Ku-Yaw Chang
Chapter 2 System Structures
62
VMware Architecture
Ku-Yaw Chang
Chapter 2 System Structures
63
2.8.3.2 Java Virtual Machine
A very popular object-oriented language

By Sun Microsystems in late 1995
Consists of



A language specification
A large API library
A specification for a Java virtual machine (JVM)
A class loader
A class verifier
A Java interpreter
Ku-Yaw Chang
Chapter 2 System Structures
64
2.8.3.2 Java Virtual Machine
A Java program consists of one or more classes.

For each class, the Java compiler produce an
architecture-neutral bytecode output (.class) file
Run on any implementation of the JVM
Ku-Yaw Chang
Chapter 2 System Structures
65
Java virtual machine
Ku-Yaw Chang
Chapter 2 System Structures
66
2.8.3.2 Java Virtual Machine
Garbage collection

Reclaim memory from objects no longer in use and
return it to the system
Just-in-time (JIT) compiler


The first time a Java method is invoked, the
bytecodes are turned into native machine language
for the host computer
These operations are cached for later use
Ku-Yaw Chang
Chapter 2 System Structures
67
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
68
2.9 Operating System Generation
Operating systems are designed to run on any of
a class of machines

must be configured for each specific computer site.
System generation (SYSGEN)

obtain information concerning the specific
configuration of the hardware system.
from a given file
ask the operator
probe the hardware directly
Ku-Yaw Chang
Chapter 2 System Structures
69
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
70
2.10 System Boot
Booting

starting a computer by loading the kernel
Bootstrap program (bootstrap loader)


code stored in ROM that is able to locate the kernel,
load it into memory, and start its execution
two-step process
A simple bootstrap loader fetches a more complex boot
program from disk
Ku-Yaw Chang
Chapter 2 System Structures
71
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
72
Summary
P.68 – P.69
Ku-Yaw Chang
Chapter 2 System Structures
73
Chapter 2 Computer System Structures
1.
2.
3.
4.
5.
6.
Operating-System Services
User Operating-System
Interface
System Calls
Types of System Calls
System Programs
Operating-System Design
and Implementation
Ku-Yaw Chang
7.
8.
9.
Operating-System Structure
Virtual Machines
Operating-System
Generation
10. System Boot
11. Summary
12. Exercises
Chapter 2 System Structures
74
Exercises
2.5
2.6
2.9
2.10
Ku-Yaw Chang
Chapter 2 System Structures
75
The End
Ku-Yaw Chang
Chapter 2 System Structures
76