OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: [email protected][email protected]...

40
OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: [email protected] Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or by appoi ntment

Transcript of OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: [email protected][email protected]...

Page 1: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

OPERATING SYSTEMS PRINCIPLES

Instructor: Xiangluo Wang

E-Mail: [email protected]

Office: Yifu A404

Office Hours: Thursdays@ 16:00-18:00,or by appointment

Page 2: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Preface• GOALS

Devoting to traditional topicsExtending & Integrating them with basic ideas in

distributed computingEmphasizing language application

• CONTENTSProcess Management and CoordinationMemory ManagementFile and I/O ManagementProtection and Security

Page 3: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Preface

• EXERCISESAnalytical contentsConstructive contentsDiscussion or speculative analysis

• APPROACH & PHILOSOPHY In-depth coverage of standard topics Integrating centralized and distributed OS issues in eac

h chapter Introducing various cases of existing os throughout the

course

Page 4: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

CHAPTER 1

THE ROLE OF OPERATING SYSTEMS

ORGANIZATION OF OPERATING SYSTEMS

OPERATING SYSTEM EVOLUTION AND

CONCEPTS

INDEX:

Page 5: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

THE ROLE OF OPERATING SYSTEMS

• Bridging the Hardware/Application Gap

• As Extended Machines

• As Virtual Machines

• As Resource Managers

Page 6: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Fetch the instruction pointed to by the program counter

Increment the program counter

Decode the current instruction

Fetch any operands referenced by the instruction

Execute the instruction

FIGURE 1-1 Basic hardware cycle

Page 7: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Main

memory

CPU Communication

devices

Secondary

storage

User

Network

FIGURE 1-2 Main components of a computer system

Main

memory

CPU

CPU

Communication

devices

Secondary

storage

FIGURE 1-3 Shared-memory multiprocessor

Page 8: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Main

memoryCPU

CPU

Communication

devices

Secondary

storage

Main

memory

FIGURE1-4 Distributed-memory multiprocessor

Main

memoryCPU

CPU

Communication

devices

Secondary

storage

Main

memory

Secondary

storage

Communication

devices

Netw

ork

FIGURE 1-5 Multicomputer

Page 9: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

LARGE DIVIDE BETWEEN HARDWARE AND APPLICATION:

Machine instructions

Read or write a value------High-level data structures

Perform arithmetic/logical operation-----Complex control flows

Main memory

A linear sequence of simple cells------programs, modules, and data structures

Secondary storage

Tracks, blocks------file

Hardware interface and I/O device

Registers-------messages

Page 10: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Three Views of operating systems

• Abstraction:

Being applied to handle complexity• Virtualization:

resource sharing• Resource management:

The problem of efficiency

KEY CONCEPTS:

Page 11: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

OS as Extended Machines

• Abstraction:package sequences of lower-level instructions into functions that can be invoked as single higher-level operations

• Making use of abstraction at many levels

Page 12: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

OS as Virtual Machines

CPU1 CPU2

CPU

Virtual memory1

Virtual memory2

Main memory

Printer1 Printer2

Printer

Application1

Time sharing

Memory management

Spooling

OS

Hardw

are

Principles of virtualization

Page 13: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Task’s VM space in Linux

User

kernel

CS

DS

BSS

HEAP

STACK

HOLE

3GB

1GB

Page 14: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

OS as Resource Managers

• Difference between devices’ performance

• Parallelism opportunities

• Scheduling policies

Page 15: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

ORGANIZATION OF OS

• Structural Organization (functional)

• Internal structure (static)Hardware InterfaceProgramming InterfaceUser Interface

• Runtime Organization

Page 16: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Structural Organization

Applications

(system and user)

OS kernel

System libraries

Hardware

User

Library calls

Kernel calls

Machine instructions

Page 17: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Hardware Interface

• Interrupts, Singularities, and TrapsExternal interrupts (Hardware)Internal interrupts

Soft interruptsSelf trapsSingularities

• Modes of Instruction Execution

X86:Ring 0—Ring 3

Page 18: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Example

• Clock interrupt in LinuxSeveral hardware clock interrupts contribute one “tick”;

One “tick” causes the change of execution mode .

• Task schedule& switchOccurring in Ring 0

• User mode& kernel mode

Linux: Ring0& Ring3;

OS2: Ring0---Ring3

Page 19: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

The Programming Interface

• The difference between kernel and library functions

• Sys-calls provided by OSs

Page 20: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Application issues call

To lib_func(params)

Body of

Lib_func()

Push params on stack

Branch to lib_func() bodyPerform service

Return from functionPop stack pointer

Nonprivileged library service

Page 21: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Application issues call

To kern_func(params)

Body of

kern_func()

Push params on stack

Branch to kern_func() body Set up regs for SVC

SVC

Pop stack pointer

Nonprivileged library service

Return from function

Kernel code

Perform service

Set nonprivileged mode

Return from SVC

Page 22: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Sys-calls

• Process management

--create/destroy, suspend/activate process

--send signal or message to process

--wait for event or signal• Memory management

--allocate/deallocate region of memory

--increase/decrease size of allocated region

Page 23: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Sys-calls

• File management

--create/destroy, open/close, move, rename file

--append data to file or concatenate files

--display content of file or directory

--display/change file attributes

Page 24: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Sys-calls

• Input/Output--read/write character or block of data from a file o

r device

--control/check status of a device

• Miscellaneous services--get current date and time

--schedule an alarm to occur

--generate various system diagnostics

Page 25: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

The User Interface

The top-level user interface remains available at all times so that users can launch, use, monitor, and manage applications and files– Text-based interface (shell)– Graphics-based interface (GUI)

Page 26: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

The Shell• Execute and manage programs

ar: create, edit,modify source files

as: compiler

ld: GNU linker

gdb: GNU DeBug

• Manipulate filesmkdir, rm, mv, rmdir, cat

• Obtain system informationwho, pwd,du, ls

Page 27: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

The Shell

• Shell scriptslocal variables

iterative statements

conditionals

arithmetic and logical operators

Wildcards

connectors

Page 28: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Runtime Organization

User process

Library or kernel call

Service routinereturn

Service as a subroutine

Process’ address space

User process (client)

Return results

Send request

Service routine

Process1’s address space

Process2’s address space

System process (server)

Service as a process

Page 29: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Benefits of the C/S approach

• Being suitable for a distributed system

• Being convenient for different types of services

• Having a greater degree of fault tolerance

• Enforcing a strict segregation of functionalities

Page 30: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

OS EVOLUTION&CONCEPTS

• Early systems

• Batch OSs

• Multiprogramming Systems

• Interactive OSs

• PC and Workstation OSs

• Real-Time OSs

• Distributed OSs

Page 31: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Early Systems

• Users interact with computations

• One at a time

• At the lowest machine level

• A standard operating procedureLoaderassemblersource programloaderexe machine code

• Initial startup (bootstrapping)

Page 32: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Batch OSs

• Automating the standard load/translate/load/execute sequence

• Job-to-job transitions automatically

• Submitting multiple jobs at the same time

• I/O processor (I/O channel)

Page 33: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Multiprogramming Systems

• A simultaneous manner

• Virtual parallelism (concurrence)

• Protection

• Process synchronization and communication

• Dynamic memory management

Page 34: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Job A

CPU

IO

Job B

Sequential execution

Job A

IOA

CPUA

CPUB

IOB

Job B

multiprogramming

CPU and I/O overlap

Page 35: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Interactive OSs

• The ability to simultaneously share a machine’s resources

• Acceptable response time to each user

• Serve processes cyclically by assigning a small portion or quantum of CPU time

Page 36: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

PC and Workstation OSs

• The development of GUIs

• Manually switching

• Implicit multiprogramming (multitasking)Being transparent to the interactive user but not to

applications

• Preemptive multiprogrammingBeing transparent not only to users but to applications

Page 37: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Real-Time OSs

• Timing constraints (deterministic deadlines)

• Concurrency (asynchronous, simultaneous)

• Strict fault tolerance and reliability requirements

• Difficult to test and certify

Page 38: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

Distributed OSs

• Loosely coupledCommunicates at a lower level (e.g., over a WAN)

• Tightly coupledhigher-level communication on top of message passing (RP

C)

• Clocks must be synchronized, accurate, and monotomic increasing

Page 39: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

EXERCISES

• Give examples of semantic gaps that must be bridged by software,including OSs at the following levels: CPU (instruction) level, main memory level, secondary storage level, I/O device level.

• What do traps and interrupts have in common? How are they different? Give an example of each.

Page 40: OPERATING SYSTEMS PRINCIPLES Instructor: Xiangluo Wang E-Mail: wx_25@yahoo.com.cnwx_25@yahoo.com.cn Office: Yifu A404 Office Hours: Thursdays@ 16:00-18:00,or.

EXERCISES

• What do multiprogramming and time-sharing have in common? How are they different? Is multiprogramming possible without interrupts? Is time-sharing possible without interrupts?