Chapter 1 Chapter 1 Operating System Operating System Overview Overview
Chapter 1 Chapter 1
Operating System OverviewOperating System Overview
OPERATING SYSTEM OVERVIEW
ContentsContents
Operating System Objectives and FunctionsOperating System Objectives and Functions
The Evolution of Operating SystemThe Evolution of Operating System
Major AchievementsMajor Achievements
Characteristics of Modern OSCharacteristics of Modern OS
ExamplesExamples (( NTNT 、、 UNIXUNIX ))
OPERATING SYSTEM OVERVIEW
1.1 Objectives and Functions (p45)1.1 Objectives and Functions (p45)
1.1.1 Overview1.1.1 Overview
1.1.2 The Operating System as a User/Computer Interface1.1.2 The Operating System as a User/Computer Interface
1.1.3 The Operating System as Resource Manager1.1.3 The Operating System as Resource Manager
1.1.4 Ease of Evolution of an Operating System1.1.4 Ease of Evolution of an Operating System
OPERATING SYSTEM OVERVIEW
An operating system is a An operating system is a programprogram that manages the that manages the computer, controls the execution of application progcomputer, controls the execution of application programs and acts as an rams and acts as an interfaceinterface(( 接口接口 ) between the us) between the user of a computer and the computer hardware.er of a computer and the computer hardware.
ObjectivesObjectives٭ ConvenienceConvenience (方便)(方便)٭ EfficiencyEfficiency (有效)(有效)٭ Ability to evolveAbility to evolve (易扩展)(易扩展)
1.1.1 Overview1.1.1 Overview
OPERATING SYSTEM OVERVIEW
1.1.2 OS as a User/Computer Interface (I)1.1.2 OS as a User/Computer Interface (I)
Figure 2.1 Layers and Views of a Computer System
Computer Hardware
Operating System
Utilities (Compiler, Database…)
Applications Programs
OperatingSystem Designer
Programmers
End User
OPERATING SYSTEM OVERVIEW
The operating system The operating system masksmasks (隐藏) (隐藏) the details of the details of the hardware from the programmerthe hardware from the programmer ,, and provideand provides the programmer with a convenient interface for uss the programmer with a convenient interface for using the system.ing the system.
The types of system interfaceThe types of system interface٭ Command interface: system command (internalCommand interface: system command (internal 、、
external)external)٭ Graphics interface: windowsGraphics interface: windows٭ Programmer interface: system call, c-libProgrammer interface: system call, c-lib
OS as a User/Computer Interface (II)OS as a User/Computer Interface (II)
OPERATING SYSTEM OVERVIEW
Services of the Operating System (I)Services of the Operating System (I)
Program creationProgram creation٭ Such as: fork (unix)Such as: fork (unix) 、、 CreateProcess (wiCreateProcess (wi
n)n)
Program executionProgram execution٭ Such as: execl, execpSuch as: execl, execp
Access to I/O devicesAccess to I/O devices٭ Such as: read/writeSuch as: read/write
Controlled access to filesControlled access to files٭ Such as: read/writeSuch as: read/write
OPERATING SYSTEM OVERVIEW
Services of the Operating System (II)Services of the Operating System (II)
System accessSystem access٭ Provide protection and authorizedProvide protection and authorized
Error detection and responseError detection and response٭ Such as: errorSuch as: error
AccountingAccounting
OPERATING SYSTEM OVERVIEW
1.1.3 OS as Resource Manager (I)1.1.3 OS as Resource Manager (I) (( p47p47 ))
Types of Resource: CPUTypes of Resource: CPU 、、 MemoryMemory 、、 DevicesDevices
CPU: chapter 3.4.5.6.9.10CPU: chapter 3.4.5.6.9.10
Memory: chapter 7.8Memory: chapter 7.8
I/O Devices: chapter 11.12I/O Devices: chapter 11.12
OPERATING SYSTEM OVERVIEW
OS as Resource Manager (II)OS as Resource Manager (II)
As a control mechanism is unusual in two respectsAs a control mechanism is unusual in two respects
٭ The OS functions in the same way as ordinary coThe OS functions in the same way as ordinary co
mputer software; that is, it is a program executed mputer software; that is, it is a program executed
by the processor.by the processor.
٭ The OS frequently The OS frequently relinquishes controlrelinquishes control ( ( 释放控释放控制制 )and must depend on the processor to allow it t)and must depend on the processor to allow it t
o o regain controlregain control (获取控制)(获取控制) ..
OPERATING SYSTEM OVERVIEW
OS as Resource Manager (III Figure 2.2)OS as Resource Manager (III Figure 2.2)
Management of CPUManagement of CPU
Management of I/O DeviceManagement of I/O Device
Management of MemoryManagement of Memory
Management of FilesManagement of Files
Concept:Concept:
٭ KernelKernel 、、 NucleusNucleus(( 内核内核 ): Always in main memo): Always in main memo
ry, contains the most-frequently-used functionsry, contains the most-frequently-used functions
OPERATING SYSTEM OVERVIEW
1.1.4 Ease of Evolution1.1.4 Ease of Evolution (( p49p49 ))
Reasons for evolutionReasons for evolution٭ hardware upgradeshardware upgrades
▪ Exp: support pagingExp: support paging٭ new servicesnew services٭ fixesfixes
ImplementsImplements٭ software engineering: modulessoftware engineering: modules 、、 layerlayer 、、 obob
ject designject design
OPERATING SYSTEM OVERVIEW
1.2 The Evolution of Operating Systems1.2 The Evolution of Operating Systems
1.2.1 Serial Processing1.2.1 Serial Processing
1.2.2 Simple 1.2.2 Simple BatchBatch Systems Systems
1.2.3 1.2.3 MultiprogrammedMultiprogrammed (多道) (多道) Batch SystemsBatch Systems
1.2.4 1.2.4 Time-SharingTime-Sharing Systems Systems
OPERATING SYSTEM OVERVIEW
1.2.1 Serial Processing(p501.2.1 Serial Processing(p50 串行处理串行处理 ))
ExampleExample٭ Input Input Calculate Calculate Print Print
ProblemsProblems٭ SchedulingScheduling: The estimated time is not accurate: The estimated time is not accurate٭ Setup timeSetup time: Between the setup procedure, if an : Between the setup procedure, if an
error occurred, then must go back to the error occurred, then must go back to the beginning of the setup sequencebeginning of the setup sequence
٭ Contradiction between human and machineContradiction between human and machine
OPERATING SYSTEM OVERVIEW
1.2.2 Simple Batch System1.2.2 Simple Batch System
ObjectivesObjectives :: Solution contradiction between humaSolution contradiction between huma
n and machinen and machine
٭ User submits the job on cards or tape to a computUser submits the job on cards or tape to a comput
er operator (use JCLer operator (use JCL (( job control language))job control language))
Implement: MonitorImplement: Monitor
OPERATING SYSTEM OVERVIEW
From the Point of View of the Monitor (p51)From the Point of View of the Monitor (p51)
MonitorMonitor is responsible for the ru is responsible for the running of every jobnning of every job
Controls are transferred between Controls are transferred between monitor and other user programsmonitor and other user programs
Interrupt processing
Device Drivers
Job Sequencing
Control Language Interpreter
User Program Area
monitor
Memory layout for a resident(驻留 ) monitor
OPERATING SYSTEM OVERVIEW
From the Point of View of the ProcessorFrom the Point of View of the Processor
When CPU runs command of monitor, the monitor When CPU runs command of monitor, the monitor
gains the control.gains the control.
When CPU runs command of user program, the useWhen CPU runs command of user program, the use
r program gains the control.r program gains the control.
Transfer the control:Transfer the control: First monitor gains the control, First monitor gains the control,
when user program load in, it gains the control, wh when user program load in, it gains the control, wh
en the user program finish or error, the monitor regen the user program finish or error, the monitor reg
ainsains (重获) (重获) the control.the control.
OPERATING SYSTEM OVERVIEW
JCL (Job Control Language)JCL (Job Control Language)
$JOB //begin$JOB //begin
$FTN //using Fortran compile and link$FTN //using Fortran compile and link
……Fortran //instructionsFortran //instructions
$LOAD //load in runable modules$LOAD //load in runable modules
$RUN //running.$RUN //running.
$END //finish do the job$END //finish do the job
OPERATING SYSTEM OVERVIEW
Other Hardware Feature Desirable(p53)Other Hardware Feature Desirable(p53)
Memory protectionMemory protection (内存保护)(内存保护) :: User space and system s User space and system space are independent.pace are independent.
٭ E.g. Hardware can detect outside accessing error.E.g. Hardware can detect outside accessing error.
Timer interruptTimer interrupt (时钟中断)(时钟中断) :: When the timer expires, an When the timer expires, an interrupt occurs.interrupt occurs.
Privileged instructionsPrivileged instructions (特权指令)(特权指令) :: Can be executed only Can be executed only by the monitor.by the monitor.
Interrupts:Interrupts:
٭ Improvement efficiencyImprovement efficiency
٭ Easy for relinquishingEasy for relinquishing (释放) (释放) and regaining controland regaining control
OPERATING SYSTEM OVERVIEW
1.2.3 Multiprogrammed Batch Systems1.2.3 Multiprogrammed Batch Systems
Read one record 0.0015 seconds
Execute 100 instructions 0.0001 seconds
Write one record 0.0015 seconds
TOTAL 0.0031 seconds
Percent CPU Utilization = 0.0001/0.0031=3.2%
Figure 2.4 System Utilization Example
UniprogrammingUniprogramming (单道) (单道) has low efficiencyhas low efficiency (效率)(效率) : : ٭ CPU---I/O contradictionCPU---I/O contradiction
OPERATING SYSTEM OVERVIEW
Multiprogramming/MultitaskingMultiprogramming/Multitasking
There are many user programs in the There are many user programs in the memory.memory.
Hardware need for Multiprogramming.Hardware need for Multiprogramming.٭ InterruptionInterruption
For example: p55 Fig2.5For example: p55 Fig2.5
OPERATING SYSTEM OVERVIEW
Example of MultiprogrammingExample of Multiprogramming
256k available memory Notes: not consider the resource competitionNotes: not consider the resource competition
JOB1 JOB2 JOB3
Type of JOB Heavy Computer Heavy I/O Heavy I/O
Duration 5min 15min 10min
Memory required 50k 100k 80k
Need disk No No Yes
Need terminal No Yes No
Need printer No No Yes
Table 2.1 Sample Program Execution Attributes
OPERATING SYSTEM OVERVIEW
AnalysisAnalysis
OPERATING SYSTEM OVERVIEW
AnalysisAnalysis
Single
٭ Processor use = 5/(5+15+10)=17%
٭ Memory use=[(50*5+100*15+80*10)/256/30] =33%
٭ Disk use=10/30=33%
٭ Printer use = 10/30=33%
٭ Total time = 5+15+10 = 30
٭ Throughput = 6 job/hour
٭ Mean response time =( 5+20+30 ) /3=18
OPERATING SYSTEM OVERVIEW
AnalysisAnalysis
MultiprogrammingMultiprogramming
٭ Processor use = 5/15=33%
٭ Memory use=[(50+100+80)*5+(100+80)*5+100*5]/256/15 =65%
٭ Disk use=10/15=67%
٭ Printer use = 10/15=67%
٭ Total time = 15
٭ Throughout = 12job/hour
٭ Mean response time =( 5+10+15 ) /3=10
OPERATING SYSTEM OVERVIEW
Sophisticated(Sophisticated( 复杂性复杂性 ) of Multiprogramming (p57)) of Multiprogramming (p57)
Memory managementMemory management
Scheduling Scheduling
٭ AlgorithmAlgorithm (算法)(算法) : The processor: The processor (处理器) (处理器) must decide which one to run.must decide which one to run.
OPERATING SYSTEM OVERVIEW
1.2.4 T1.2.4 Time-Sharing Systemsime-Sharing Systems
Multiple users simultaneouslyMultiple users simultaneously (同时) (同时) access the system thaccess the system th
rough terminals(rough terminals( 终端终端 ))
Concepts: Concepts:
٭ time slicetime slice (时间片)(时间片) : q: q
٭ user numuser num (用户数)(用户数) : n: n
٭ response timeresponse time (响应时间)(响应时间) : t: t
٭ t=n×qt=n×q
Mode: multi-terminalsMode: multi-terminals 、、 multi-windowsmulti-windows
OPERATING SYSTEM OVERVIEW
Batch Multiprogramming vs Timer SharingBatch Multiprogramming vs Timer Sharing
Batch Multiprogramming
Time Sharing
Principal objecPrincipal objectivetive
Maximize processor Maximize processor useuse
Minimize response Minimize response timetime
Source of instrSource of instruction to operauction to operating systemting system
Job control language Job control language commands provided commands provided with the jobwith the job
Commands entered Commands entered at the terminalat the terminal
OPERATING SYSTEM OVERVIEW
Reducing the Swapping Loads by Partial SwappingReducing the Swapping Loads by Partial Swapping (( p59p59 ))
Reducing the spending for accessing disk
OPERATING SYSTEM OVERVIEW
1.3 Major Achievements1.3 Major Achievements (( p60p60 ))
1.3.1 Processes(1.3.1 Processes( 进程进程 ))
1.3.2 Memory management1.3.2 Memory management
1.3.3 Information protection and security1.3.3 Information protection and security
1.3.4 Scheduling and resource management1.3.4 Scheduling and resource management
1.3.5 System structure1.3.5 System structure
OPERATING SYSTEM OVERVIEW
1.3.1 Processes1.3.1 Processes
A program in executionA program in execution
The animated spiritThe animated spirit (活动精灵) (活动精灵) of a programof a program
The entityThe entity (实体) (实体) that can be assignedthat can be assigned (分派) (分派) to and eto and e
xecuted on a processorxecuted on a processor
Three major types of computer systemThree major types of computer system
٭ Multiprogramming batch operationMultiprogramming batch operation
٭ Time sharingTime sharing
٭ Real-time transactionReal-time transaction (处理) (处理) systemssystems
OPERATING SYSTEM OVERVIEW
Errors May Happen in MultiprogrammingErrors May Happen in Multiprogramming
Improper synchronizationImproper synchronization (同步)(同步) : Signals being : Signals being
lost or duplicatelost or duplicate (重复) (重复) signals being received.signals being received.
Failed mutual exclusionFailed mutual exclusion(( 失败的互斥失败的互斥 ))
NondeterminateNondeterminate (不确定)(不确定) program operationprogram operation: T: T
he result is not uniquehe result is not unique
DeadlocksDeadlocks (死锁)(死锁)To solute these problems, introduce process conceptTo solute these problems, introduce process concept
OPERATING SYSTEM OVERVIEW
Process entity(Process entity( 实体实体 ))
An executable programAn executable program
The associated data needed by the programThe associated data needed by the program
The execution context(The execution context( 上下文上下文 ) of the program) of the program
OPERATING SYSTEM OVERVIEW
Process Image and Process SwitchProcess Image and Process Switch (切换)(切换) (p63)(p63)
OPERATING SYSTEM OVERVIEW
1.3.2 Memory Management1.3.2 Memory Management
Process isolationProcess isolation (隔离)(隔离)Automatic allocation and managementAutomatic allocation and management
Support of modularSupport of modular (模块化) (模块化) programmingprogramming
Virtually memoryVirtually memory
Long-term storageLong-term storage
Protection and access controlProtection and access control (访问控制)(访问控制)
OPERATING SYSTEM OVERVIEW
Fig 2.10 Two Views of a Storage System
Virtual Processor
Real Processor
Mapper (AddressTranslate)
Main Memory
AuxiliaryMemory
VirtualMemory
Files
(a) User’s View
(b) Operating System Designer’s View
VirtualAddress
MemoryAddress Swapping
Read, Write Copy
Long-term Store
OPERATING SYSTEM OVERVIEW
1.3.3 Information Protection and Security1.3.3 Information Protection and Security
Access controlAccess control: for various resources in the system: for various resources in the system
Information flow controlInformation flow control (信息流控)(信息流控) : to guarant: to guarant
ee the data to send to destinationee the data to send to destination
CertificationCertification (认证)(认证)
OPERATING SYSTEM OVERVIEW
1.3.4 Scheduling and Resource Management1.3.4 Scheduling and Resource Management (( p66p66 ))
Three factors must be considerThree factors must be consider
٭ FairnessFairness
٭ Differential responsivenessDifferential responsiveness(( 区分服务区分服务 ): ): e.g.e.g. If a process i If a process is waiting for the use of an I/O device, the operating systes waiting for the use of an I/O device, the operating system may wish to schedule that process for execution as soon m may wish to schedule that process for execution as soon as possible in order to free up the device for later demandas possible in order to free up the device for later demands from other processes.s from other processes.
٭ EfficiencyEfficiency: Maximize throughput(: Maximize throughput( 吞吐量吞吐量 ), minimize res), minimize response time, accommodateponse time, accommodate (容纳) (容纳) as many users as posas many users as possiblesible
OPERATING SYSTEM OVERVIEW
ShortShort -- term queueterm queue
٭ Algorithm used to use: round robinAlgorithm used to use: round robin (轮转)(轮转) LongLong -- term queueterm queue
٭ Algorithm used to use: FIFOAlgorithm used to use: FIFO
Interrupt handler: the method for get the controlInterrupt handler: the method for get the control
Service call handlerService call handler (系统服务处理)(系统服务处理) : the entry point into : the entry point into
the operating systemthe operating system
Some ConceptsSome Concepts (( p67p67 ))
OPERATING SYSTEM OVERVIEW
Fig 2.11 Key elements of an Operating System for Multiprogramming
Service CallHandler
InterruptHandler
Long-term Queue
Short-term Queue
Short-Term Scheduler
I/O queue
OS
OPERATING SYSTEM OVERVIEW
ModulesModules (模块化) (模块化) structure: only suitable for smstructure: only suitable for sm
all system; for complex system, difficult for debugall system; for complex system, difficult for debug
HierarchicalHierarchical (层) (层) structurestructure
٭ Level n provides service for level n+1Level n provides service for level n+1
System Structure(p68System Structure(p68 系统结构系统结构 ))
OPERATING SYSTEM OVERVIEW
Hierarchy (Table 2.4)Hierarchy (Table 2.4)
LevelLevel NameName ObjectsObjects Example OperationsExample Operations
1313 ShellShell User programmingUser programming Statements in shell languageStatements in shell languageenvironmentenvironment
1212 User processesUser processes User processesUser processes Quit, kill, suspend, resumeQuit, kill, suspend, resume
1111 DirectoriesDirectories DirectoriesDirectories Create, destroy, attach, detach,Create, destroy, attach, detach,search, listsearch, list
1010 DevicesDevices External devicesExternal devices Open, close,Open, close,as printer, displaysas printer, displays read, writeread, writeand keyboardsand keyboards
99 File systemFile system FilesFiles Create, destroy, open, closeCreate, destroy, open, closeread, writeread, write
88 CommunicationsCommunications PipesPipes Create, destroy, open, close,Create, destroy, open, close,read, writeread, write
OPERATING SYSTEM OVERVIEW
HierarchyHierarchy
LevelLevel NameName ObjectsObjects Example Operations Example Operations
77 Virtual MemoryVirtual Memory Segments, pagesSegments, pages Read, write, fetch Read, write, fetch
66 Local secondaryLocal secondary Blocks of data, deviceBlocks of data, device Read, write, allocate, freeRead, write, allocate, freestorestore channelschannels
55 Primitive processes Primitive process,Primitive processes Primitive process, Suspend, resume, wait, Suspend, resume, wait, semaphores, readysemaphores, ready signalsignal listlist
OPERATING SYSTEM OVERVIEW
Hierarchy (Hardware)Hierarchy (Hardware)
LevelLevel NameName ObjectsObjects Example Operations Example Operations
44 InterruptsInterrupts Interrupt-handlingInterrupt-handling Invoke, mask, unmask, Invoke, mask, unmask, retryretry
programsprograms
33 ProceduresProcedures Procedures, call stack, Procedures, call stack, Mark stack, call, Mark stack, call, returnreturn
displaydisplay
22 Instruction SetInstruction Set Evaluation stack, micro-Evaluation stack, micro- Load, store, add, Load, store, add, subtractsubtract
program interpreter,program interpreter, branch branchscalar and array datascalar and array data
11 Electronic circuitsElectronic circuits Registers, gates, buses,Registers, gates, buses, Clear, transfer, Clear, transfer, activate,activate,
etc.etc. complement complement
OPERATING SYSTEM OVERVIEW
1.4.1 Microkernel architecture1.4.1 Microkernel architecture (微内核结构)(微内核结构)
1.4.2 Multithreading1.4.2 Multithreading (多线程)(多线程)
1.4.3 Symmetric multiprocess1.4.3 Symmetric multiprocess (对称多处理)(对称多处理)
1.4.4 Distributed operating systems1.4.4 Distributed operating systems (分布式系统)(分布式系统)
1.4.5 Object-oriented design1.4.5 Object-oriented design (对象设计)(对象设计)
1.4 Characteristics of Modern OS (p71)1.4 Characteristics of Modern OS (p71)
OPERATING SYSTEM OVERVIEW
Assigns only a few essentialAssigns only a few essential (必要的) (必要的) functions to functions to
the kernel, including address spaces, interprocess cthe kernel, including address spaces, interprocess c
ommunication(IPC)ommunication(IPC) (进程间通信)(进程间通信) , and basic sch, and basic sch
eduling.eduling.
Simplifies implementation, provides flexibilitySimplifies implementation, provides flexibility (伸(伸缩性)缩性) and well suited to a distributed environment.and well suited to a distributed environment.
1.4.1 Microkernel 1.4.1 Microkernel
OPERATING SYSTEM OVERVIEW
1.4.2 Multithreading1.4.2 Multithreading
ThreadThread :: a dispatchablea dispatchable (分派) (分派) unit of workunit of work
ProcessProcess :: a collection of one or more threads and aa collection of one or more threads and a
ssociatedssociated (相关) (相关) system resourcessystem resources
Introduce thread for improve the concurrence degreIntroduce thread for improve the concurrence degre
ee (并发度)(并发度)E.g.E.g. :: a database server accept many connection rea database server accept many connection re
quest and use multithread for processquest and use multithread for process
OPERATING SYSTEM OVERVIEW
1.4.3 Symmetric Multiprocessing (SMP p73)1.4.3 Symmetric Multiprocessing (SMP p73)
A computer hardware architecture and also to the operating A computer hardware architecture and also to the operating system behavior that reflects that architecture.system behavior that reflects that architecture.
٭ Multiple processorsMultiple processors
٭ These processors share the same main memory and I/O faThese processors share the same main memory and I/O fa
cilities, interconnected by a bus or other internal connecticilities, interconnected by a bus or other internal connecti
on scheme.on scheme.
٭ All processors can perform the same functionsAll processors can perform the same functions (( hence thence t
he term symmetriche term symmetric ))
OPERATING SYSTEM OVERVIEW
SMP vs Single ProcessorSMP vs Single Processor
Performance: parallel and concurrencePerformance: parallel and concurrence (并行与并(并行与并发)发)
Reliability/AvailabilityReliability/Availability (可靠性(可靠性 // 可用性)可用性)Incremental growthIncremental growth (可伸展性)(可伸展性) : enhance the per: enhance the per
formance of a system by adding an additional proceformance of a system by adding an additional proce
ssorssor
OPERATING SYSTEM OVERVIEW
SMP vs Single Processor (Figure 2.12)SMP vs Single Processor (Figure 2.12)
OPERATING SYSTEM OVERVIEW
1.4.4 Distributed Operating System1.4.4 Distributed Operating System
Data distributedData distributed
Task distributedTask distributed
TransparentTransparent (透明)(透明) : a multi-processor with a : a multi-processor with a
single processor charactersingle processor character
High throughout and reliabilityHigh throughout and reliability
OPERATING SYSTEM OVERVIEW
1.4.5 Object Design1.4.5 Object Design
Encapsulation and inheritEncapsulation and inherit (封装和继承)(封装和继承)
Good scalabilityGood scalability (尺度特征)(尺度特征)