Download Operating System Concepts

Document related concepts

Plan 9 from Bell Labs wikipedia , lookup

DNIX wikipedia , lookup

Copland (operating system) wikipedia , lookup

RSTS/E wikipedia , lookup

Burroughs MCP wikipedia , lookup

VS/9 wikipedia , lookup

Process management (computing) wikipedia , lookup

Security-focused operating system wikipedia , lookup

Unix security wikipedia , lookup

Spring (operating system) wikipedia , lookup

CP/M wikipedia , lookup

Distributed operating system wikipedia , lookup

Paging wikipedia , lookup

Transcript
Operating System Course
開放課程:http://lms.nthu.edu.tw/course/
Jia-Shung Wang
Department of Computer Science
National Tsing Hua University
Textbook: (A. Silberschatz, P. Galvin and G. Gagne)
1. Operating System Concepts, 8th Edition (International Student), John
Wiley & Sons, Inc., 2010. OR
2. Operating System Principles, 7th Edition (Wiley Asia Student), John
Wiley & Sons, Inc., 2006. OR
3. Operating System Concepts, 7th Edition, John Wiley & Sons, Inc, 2005.
https://www.wileyplus.com/WileyCDA/Section/Operating-SystemConcepts-International-Student-Version-8th-Edition.id-402503.html
2017/5/6
OS0-2011
1
2017/5/6
OS0-2011
2
Scoring




Midterm Exam (32%) 7 November, 2011
Final Exam (36%)
9 January, 2012
Exercises and Quiz (14+6 %)
Nachos Projects (5+7 %)
Office Hours
Friday
2017/5/6
10:00~11:30
OS0-2011
3
Projects
Nachos
Project 1: Multiprogramming
due: October 17
Project 2: CPU Scheduling
due: December 19
2017/5/6
OS0-2011
4
Overview (1)
Operating systems are an essential part of any
computer system.
Similarly, a course on operating systems is an
essential part of any computer-science education.
This field is undergoing change at a rapid rate, as
computers are now prevalent in virtually every
application, from games for children through the
most sophisticated planning tools for governments
and multinational firms.
Prerequisites: we assume that the reader is familiar
with basic data structures, computer organization,
and a high-level language, such as C.
2017/5/6
OS0-2011
5
Overview (2)
Concepts are presented using intuitive descriptions.
Important theoretical results are covered, but
formal proofs are omitted.
The bibliographical notes contain pointers to
research papers in which results were first
presented and proved, as well as references to
material for further reading.
In place of proofs, figures and examples are used
to suggest why we should expect the result in
question to be true.
2017/5/6
OS0-2011
6
Overview (3)
The fundamental concepts and algorithms covered
in the book are often based on those used in
existing commercial operating systems.
Our aim is to present these concepts and
algorithms in a general setting that is not tied to
one particular operating system.

Present a large number of examples that pertain to
the most popular operating systems, including Sun
Microsystems' Solaris; Linux; Mach; Microsoft MSDOS, Windows NT, Windows 2000, and Windows XP;
DEC VMS and TOPS-20; IBM OS/2; and Apple Mac
OS X.
2017/5/6
OS0-2011
7
Overview (4)
The content of the text corresponds to the
suggestions from Computing Curricula 2001
for teaching operating systems, published by
the Joint Task Force of the IEEE Computing
Society and the Association for Computing
Machinery (ACM).
2017/5/6
OS0-2011
8
Operating-System Environments (1)
 The text also provides several example programs written in
C and Java. These programs are intended to run in the
following programming environments:
•
Windows systems: Win32 API, which provides a
comprehensive set of functions for managing processes,
threads, memory, and peripheral devices.
•
POSIX: POSIX (Portable Operating System Interface)
represents a set of standards implemented primarily for
UNIX-based operating systems. POSIX-compliant systems
must implement the POSIX core standard (POSIX .1)--Linux,
Solaris, and Mac OS X. POSIX also defines several
extensions to the standards, including real-time extensions
(POSIX 1.b) and an extension for a threads library (POSIX
1.c, better known as Pthreads)
2017/5/6
OS0-2011
9
Operating-System
Environments (2)
•
Java: Java is a widely used programming
language with a rich API and built-in language
support for thread creation and management.
Java programs run on any operating system
supporting a Java virtual machine (or JVM).
2017/5/6
OS0-2011
10
Contents (8th ed.)
PART ONE
Chapter 1
Chapter 2
OVERVIEW
Introduction
Operating-System Structures
PART TWO
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
PROCESS MANAGEMENT
Processes
Threads
CPU Scheduling
Process Synchronization
Deadlocks
PART THREE
Chapter 8
STORAGE MANAGEMENT
Memory Management
2017/5/6
OS0-2011
11
Chapter 9
Virtual Memory
PART FOUR
Chapter 10
Chapter 11
Chapter 12
Chapter 13
STORAGE MANAGEMENT
File-System Interface
File-System Implementation
Mass-Storage Structure
I/O Systems
PART FIVE
Chapter 14
Chapter 15
PROTECTION AND SECURITY
Protection
Security
PART SIX
Chapter 16
DISTRIBUTED SYSTEMS
Distributed System Structures
2017/5/6
OS0-2011
12
Chapter 17
Chapter 18
Distributed File Systems
Distributed Coordination
PART SEVEN
Chapter 18
Chapter 18
SPECIAL-PURPOSE SYSTEMS
Real-Time Systems
Multimedia Systems
PART EIGHT CASE STUDIES
Chapter 20
Chapter 21
Chapter 22
Appendix
Appendix
Appendix
2017/5/6
The Linux System
Windows XP, 7
Influential Operating Systems
A BSD Unix
B The Mach System
The Nachos System
OS0-2011
13
Syllabus
1. Overview (2.5 weeks)
2. Processes
3. Multithreaded Programming
4. Process Scheduling (1.5 weeks)
5. DeadLocks
6. Process Synchronization (2 weeks) Quiz
7. Memory Management
8. Virtual-Memory (2 weeks)
9. File Systems Interface and Implementation (1.5 weeks)
10. Secondary-Storage Structure
11. I/O Systems
Case Studies: Linux
16.5 weeks
2017/5/6
OS0-2011
14
The 7th Edition (1)
Reorganized the overview material in Chapters 1 and 2
Added two new chapters on special purpose systems (real-time
embedded systems and multimedia systems)
1: provides a grand tour of the major operating-system
components
2: is a revised version of old Chapter 3, provides updated
coverage of virtual machines
3&4 (Processes, Threads): POSIX, Win32 APIs, and Java
thread
5(CPU Scheduling): processor affinity, load-balancing
algorithms, and thread scheduling
6(Process Synchronization): Linux kernel and Pthreads API
2017/5/6
OS0-2011
15
The 7th Edition (2)
7 (Deadlocks): multithreaded Pthread
8 (Main Memory): overlays, segmentation (Pentium,
Linux)
9 (Virtual Memory) allocating memory within the kernel
discusses the buddy algorithm and slab allocator.
10 (File-System Interface): Windows XP ACLs
11 (File-System Implementation) WAFL file system and ZFS
file system
12 (Mass-Storage Structure): new RAID technology
2017/5/6
OS0-2011
16
The 8th Edition (1)
1: multicore CPUs, open-source operating systems
2: updated coverage of virtual machines, multicore
CPUs, the GRUB boot loader, OS debugging
3&4 (Processes, Threads): pipes, programming for
multicore systems
5(CPU Scheduling): virtual machine scheduling,
multicore architectures
6(Process Synchronization): transaction memory
2017/5/6
OS0-2011
17
The 8th Edition (2)
8 (Main Memory): discussions of NUMA
9 (Virtual Memory) Solaris 10 memory management
11 (File-System Implementation) full description
of Sun’s ZFS file system
12 (Mass-Storage Structure): iSCSI, ZFS pool
13 (I/O Systems): PCI Express, Hyper-Transport
2017/5/6
OS0-2011
18
Operating-System Structures
System Components
Operating System Services
System Calls
System Programs
System Structure
Virtual Machines
System Design and Implementation
System Generation
2017/5/6
OS0-2011
19
Common System Components
Process Management
Main Memory Management
File Management
I/O System Management
Secondary Management
Networking
Protection System
Command-Interpreter System
2017/5/6
OS0-2011
20
Historical Perspective
Mainframe: Batch
Mainframe: Multiprogramming
Mainframe: Time-Sharing
Computer-system Architecture

Single-processor Systems
 PCs

Multiprocessor Systems
 Parallel Systems or Tightly Coupled Systems

Cluster Systems
2017/5/6
OS0-2011
21
Mainframe: Batch Systems
Main job of early OS: automatically transfer control
from one job to the next. (resident in memory)
To speed up processing, jobs with similar needs
were batched together and were running through
the computer as a group.
A batch operating system



2017/5/6
Programmers submit jobs (program, data, control cards)
Operator sort jobs into batches with similar requirements
(Fortran, Cobol)
OS transfers control from one job the the next.
OS0-2011
22
$END
$RUN
$LOAD
$FNT
$JOB
data for the program
program to be compiled
2017/5/6
OS0-2011
23
Memory Layout for a Simple Batch
System
2017/5/6
OS0-2011
24
Lack of interaction between the user and the
job while that job is executing.
CPU is often idle


I/O devices: card reader/printer
I/O speed << CPU speed (at least 1:1000)
Introduction of Disk technology



Spooling (Simultaneous Peripheral Operation OnLine)
I/O is done with no CPU intervention
CPU just needs to be notified when I/O is done
2017/5/6
OS0-2011
25
Disk
Card Reader
CPU
Line Printer
Spooling
2017/5/6
OS0-2011
26
Spooling overlaps the I/O of one job with the
computation of other jobs.

The spooler may be reading the input of one job
while printing the output of a different job.
By overlaps, spooling keeps both the CPU and
the I/O devices working at much higher rates.
2017/5/6
OS0-2011
27
Mainframe: Multiprogramming
Batched Systems
Spooling provides an important data structure: a job
pool, which contains jobs waiting on disk, ready to run.
Job scheduling becomes possible: OS can select
which job to run next, to increase CPU utilization.
The most important aspect of job scheduling is the
ability to multiprogram : OS keeps several jobs in
memory at a time.
 Multiprogramming organizes jobs such that CPU
always has one to execute. (When one job is waiting
for I/O, CPU switches to another.)
2017/5/6
OS0-2011
28
Multiprogramming Systems
Several jobs are kept in main memory at the same
time, and the CPU is multiplexed among them.
2017/5/6
OS0-2011
29
OS Features Needed for
Multiprogramming
I/O routine supplied by the system.
Memory management – the system must
allocate the memory to several jobs.
CPU scheduling – the system must choose
among several jobs ready to run.
Allocation of devices.
2017/5/6
OS0-2011
30
Job Scheduling
Operating System
CPU Scheduling
Job 1
CPU
Job 2
Job 3
Job 4
2017/5/6
OS0-2011
Job pool
31
Mainframe: Time-Sharing Systems
 Disadvantages of a multiprogrammed batched
systems


No interaction with users: users must set up control cards
for all possible outcomes.
Statically debugging: long turnaround time inhibits
experimentation. (But, it instills good discipline of
writing/testing)
An interactive (or hand-on) system: allows on-line
communication between users and the system.
(Usually, keyboard/screen are used. Users can see
results immediately.)
2017/5/6
OS0-2011
32
Time-sharing (or multi-tasking): an
extension of multiprogramming.


CPU switches among jobs frequently such that users
may interact with programs.
Switch job when
 finish
 waiting I/O
 a short period of time
Early OS: single user, interactive
Batch: good CPU utilization, no interaction
Time-sharing: interaction, reasonable cost
Combine: Batch + Time sharing (IBM OS/360)
2017/5/6
OS0-2011
33
Time-sharing System
CPU Scheduling and multiprogramming provide
each user with a small portion of a time-shared
computer.
CPU-bound and I/O-bound process
Memory management and Protection
Virtual memory
File system, Disk management
Concurrent execution
Process synchronization and Deadlock
2017/5/6
OS0-2011
34
The Movement of OS
MULTICS (1965-1970 MIT) for GE 645
UNIX (Ken Thompson, 1970 Bell Lab) for DEC PDP-11, Clanguage
UNIX-like OS: System V, XENIX, BSD, Solaris, Linux, Cloud OS
Workstation: Solaris, RS/6000, NT
PC: Windows, Unix, Linux, OS/2, MacOS, …
Hand-held: Palm, Windows CE, Linux, Symbian, iOS,
Android, …
Embedded Systems: Linux, Wind River, …
2017/5/6
OS0-2011
35
Computer-system Architecture
Single-processor Systems

PCs
Multiprocessor Systems

2017/5/6
Parallel Systems or Tightly Coupled Systems
OS0-2011
36
Desktop Systems
Personal computers (PC) – computer system
dedicated to a single user.
I/O devices – keyboards, mice, display screens,
small printers.
User convenience and responsiveness.
Can adopt technology developed for larger
operating system, often individuals have sole use of
computer and do not need advanced CPU utilization
of protection features.
May run several different types of operating
systems (Windows, MacOS, UNIX, Linux)
2017/5/6
OS0-2011
37
Personal-Computer Systems
PCs: appeared in the 1970s, instead of maximizing
CPU and peripheral utilization, the systems opt for
maximizing user convenience and responsiveness.
MS-DOS, OS/2, MacOS, Windows, Linux, Android, …
GUI
Lack of file protection at first: destroy data, system
or even worldwide networks via virus mechanisms.
LAN, Internet, browser, Social Networks, …
2017/5/6
OS0-2011
38
Parallel Systems (1)
Multiprocessor systems with more than one
CPU in close communication.
Tightly coupled system – processors share
memory and a clock; communication usually
takes place through the shared memory.
Advantages of parallel systems:



Increased throughput
Economical
Increased reliability
 graceful degradation
2017/5/6
OS0-2011
39
Parallel Systems (2)
Symmetric multiprocessing (SMP)



Each processor runs an identical copy of the operating
system.
Many processes can run at once without performance
deterioration.
Most modern operating systems support SMP, Solaris
2, …
Asymmetric multiprocessing



2017/5/6
Each processor is assigned a specific task; master
processor schedules and allocated work to slave
processors.
More common in extremely large systems
Grid computing
OS0-2011
40
Symmetric Multiprocessing Architecture
All processors are peer; no master-slave relationship exists between processors.
Shared dynamically
Among PEs
2017/5/6
OS0-2011
41
Uniform Memory Access VS.
Non-Uniform Memory Access (NUMA)
Uniform Memory Access (UMA)

Access to any RAM from any CPU (or Core)
takes the same amount of time.
Non-Uniform Memory Access (NUMA)
• Some part of memory may take longer access
than other parts, creating a performance
penalty. (Section 9.5.4)
2017/5/6
OS0-2011
42
Multi-Core
On-chip communication is faster than
between-chip communication
Power Consumption
• One chip with multiple cores uses significantly
less power than multiple single-core chips.
• Multicore systems are well suited for server
systems such as database and Web servers.
2017/5/6
OS0-2011
43
A Dual-Core Design
other designs:
A combination of
local and shared caches
2017/5/6
blade servers:
Each blade–processor board
boots independently and
run its own OS.
OS0-2011
44
Clustered Systems
Definition: Cluster computers share storage and are
closely linked via a local area network (LAN) or a
faster interconnect, such as InfiniBand.
Provides high reliability
Asymmetric clustering: one server runs the application
while other servers standby.
Symmetric clustering: two or more hosts are running
application and are monitoring each other.
2017/5/6
OS0-2011
45
Parallelization and
Distributed Lock Management
Parallelization: divide a program in several
components and run in parallel
Parallel clusters
Distributed Lock Management (DLM): To
provide the shared access to data, the system
must also supply access control and locking to
ensure that no conflicting operations occur.
2017/5/6
OS0-2011
46
Beowulf Clusters and SANs
Designed for solving high-performance
computing task.
Low-cost strategy: PC, Linux, open-source
software, LAN, …
Storage-area networks (SANs)
2017/5/6
OS0-2011
47
Cloud OS, ITRI
•
Virtualization Platform
– CPUs
– Storage (Filesystems)
– Network
•
VM
HC Virtual
Cluster
AppX
Virtual
Cluster
VM
VM
VM
Power Management
Security
– Hypervisor protection
– Compartmentalization between Clusters
•
Bkup
Virtual
Cluster
Resource Management
– Provisioning of virtual clusters
– Physical machine load balancing
– Network traffic load balancing
•
•
Mail
Virtual
Cluster
CCMA Infrastructure SW
System Management
– FCAPS
•
High Availability
– Physical component failure does not
interrupt availability of virtual resources
•
Cloud Applications management
Physical
Node
Physical
Node
Physical
Node
Physical
Node
Operating System Components
Timesharing (multitasking) is logical extension in
which CPU switches jobs so frequently that users can
interact with each job while it is running, creating
interactive computing





Response time should be < 1 second
Each user has at least one program executing in memory
process
If several jobs ready to run at the same time  CPU
scheduling
If processes don’t fit in memory, swapping moves them in
and out to run
Virtual memory allows execution of processes not
completely in memory
2017/5/6
OS0-2011
49
Dual-mode
Dual-mode operation allows OS to protect itself and
other system components


User mode and kernel mode
Mode bit provided by hardware
 Provides ability to distinguish when system is running user code or
kernel code
 Some instructions designated as privileged, only executable in kernel
mode
 System call changes mode to kernel, return from call resets it to user
2017/5/6
OS0-2011
50
System Structures
designer point of view
Simple structure: DOS
Layered approach
Microkernels
2017/5/6
OS0-2011
51
MS-DOS Layer Structure
application program
resident system program
MS-DOS
device drivers
ROM BIOS device drivers
2017/5/6
OS0-2011
52
Original UNIX System Structure
The users
(2)
system
programs
(1)
kernel
shells and commands
compilers and interpreters
system libraries
system-call interface to the kernel
signals
terminal
file system CPU scheduling
swapping page replacement
Handling
char I/O
terminal
drivers
block I/O
demand paging
disk and tape
virtual
drivers
memory
kernel interface to the hardware
hardware
2017/5/6
terminal controllers device controllers
terminals
OS0-2011
devices and tapes
memory controllers
physical memory
53
System Implementation
Traditionally written in assembly language,
operating systems can now be written in higherlevel languages.
Code written in a high-level language:

can be written faster

is more compact

is easier to understand and debug
An operating system is far easier to port (move to
some other hardware) if it is written in a high-level
language.
2017/5/6
OS0-2011
54
System Generation (SYSGEN)
Operating systems are designed to run on any of a
class of machines; the system must be configured for
each specific computer site.
SYSGEN program obtains information concerning
the specific configuration of the hardware system.

CPU type, memory size, devices, OS options, OS
parameters, etc.
Booting – starting a computer by loading the kernel.
Bootstrap program – code stored in ROM that is able
to locate the kernel, load it into memory, and start
its execution.
2017/5/6
OS0-2011
55
Bill Gates VS. Jack Welch
 比爾蓋茲:如果通用汽車能使他們的科技進展速度如同資訊產業的進展速度,那
麼我們今天的汽車售價僅需廿五美元,每一加侖汽油可以跑一千英哩。
傑克威爾許:如果通用汽車發展科技的方式
如同微軟一樣,那麼我們今天的汽
車就有以下特色
•
汽車每天會毫無理由的撞毀(Crash)兩次。
•
每一次道路標線重漆或是交通標識改變時,你就必須買一輛新車。
•
有時候你的汽車會毫無理由在高速公路上停下來,你只好接受事實,然後重新發
動,重新上路。
•
有時候,你操控汽車右轉、左轉或倒車時,可能會造成汽車熄火,而且拒絕再度
發動,唯一解決方法是重新安裝引擎。
•
每一輛車只能有一名乘客,除非你買的是汽車95/98或汽車NT/2000。即使如此,
你還得加座椅,座椅的價格和汽車差不多。
•
麥金塔製造一種非常耐用的汽車,由太陽能推動,速度快五倍,使用方式易學易熟練,
但它只使用百分之五的道路。
2017/5/6
OS0-2011
56
Bill Gates VS. Jack Welch
•
原先儀表板上所有的指示燈,例如:油量、水量、溫度等,現在濃縮成一個,上面
標示為一般汽車錯誤。
•
新的座椅要求每個人的臀部要一樣大。
•
安全氣囊彈出之前會問:「你確定嗎?」
•
有時候你的汽車會毫無理由將你鎖在門外,唯一的進入方式是同一時間右手拉著車
門開關、左手轉動車鑰匙、口內咬著汽車天線。
•
不管車主願不願意,通用汽車會要求車主還必須購買由通用汽車子公司出版的導航
地圖。如果車主不願意使用並將它丟掉,汽車的效能會銳減百分之五十,如果車主
使 用別家出版的導航地圖,汽車撞毀的次數會增加。
•
每一次通用汽車推出新車型時,車主必須重新學習駕駛方式,因為新車和舊車的所
有控制方式都不相同。
•
你必須按開始才能關閉引擎。
2017/5/6
OS0-2011
57