• 沒有找到結果。

Operating-System

N/A
N/A
Protected

Academic year: 2022

Share "Operating-System "

Copied!
23
0
0

加載中.... (立即查看全文)

全文

(1)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Contents

1. Introduction

2. Computer-System Structures 3. Operating-System Structures 4. Processes

5. Threads

6. CPU Scheduling

7. Process Synchronization 8. Deadlocks

9. Memory Management 10.Virtual Memory 11.File Systems

Chapter 3

Operating-System

Structures

(2)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Operating-System Structures

ƒ Goals: Provide a way to understand an operating systems

ƒ Services

ƒ Interface

ƒ System Components

ƒ The type of system desired is the basis for choices among various algorithms and strategies!

System Components – Process Management

ƒ Process Management

ƒ Process: An Active Entity

ƒ Physical and Logical Resources

ƒ Memory, I/O buffers, data, etc.

ƒ Data Structures Representing Current Activities:

Program Counter Stack

Data Section CPU Registers

….

And More

Program (code) +

(3)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Components – Process Management

ƒ Services

ƒ Process creation and deletion

ƒ Process suspension and resumption

ƒ Process synchronization

ƒ Process communication

ƒ Deadlock handling

System Components – Main- Memory Management

ƒ Memory: a large array of words or bytes, where each has its own address

ƒ OS must keep several programs in memory to improve CPU utilization and user response time

ƒ Management algorithms depend on the hardware support

ƒ Services

ƒ Memory usage and availability

ƒ Decision of memory assignment

ƒ Memory allocation and deallocation

(4)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Components – File Management

ƒ Goal:

ƒ A uniform logical view of information storage

ƒ Each Medium controlled by a device

ƒ Magnetic tapes, magnetic disks, optical disks, etc.

ƒ OS provides a logical storage unit: File

ƒ Formats:

ƒ Free form or being formatted rigidly.

ƒ General Views:

ƒ A sequence of bits, bytes, lines, records

System Components – File Management

ƒ Services

ƒ File creation and deletion

ƒ Directory creation and deletion

ƒ Primitives for file and directory manipulation

ƒ Mapping of files onto secondary storage

ƒ File Backup

* Privileges for file access control

(5)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Components – I/O System Management

ƒ Goal:

ƒ Hide the peculiarities of specific hardware devices from users

ƒ Components of an I/O System

ƒ A buffering, caching, and spooling system

ƒ A general device-driver interface

ƒ Drivers

System Components –

Secondary-Storage Management

ƒ Goal:

ƒ On-line storage medium for programs & data

ƒ Backup of main memory

ƒ Services for Disk Management

ƒ Free-space management

ƒ Storage allocation, e.g., continuous allocation

ƒ Disk scheduling, e.g., FCFS

(6)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Components – Networking

ƒ Issues

ƒ Resources sharing

ƒ Routing & connection strategies

ƒ Contention and security

ƒ Network access is usually

generalized as a form of file access

ƒ World-Wide-Web over file-transfer protocol (ftp), network file-system (NFS), and hypertext transfer protocol (http)

System Components – Protection System

ƒ Goal

ƒ Resources are only allowed to accessed by authorized processes.

ƒ Protected Resources

ƒ Files, CPU, memory space, etc.

ƒ Services

ƒ Detection & controlling mechanisms

ƒ Specification mechanisms

ƒ Remark: Reliability!

(7)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Components –

Command-Interpreter system

ƒ Command Interpreter

ƒ Interface between the user and the operating system

ƒ Friendly interfaces

ƒ Command-line-based interfaces or mused-based window-and-menu interface

ƒ e.g., UNIX shell and command.com in MS-DOS

Get the next command Execute the command User-friendly?

Operation-System Services

ƒ Program Execution

ƒ Loading, running, terminating, etc

ƒ I/O Operations

ƒ General/special operations for devices:

ƒ Efficiency & protection

ƒ File-System Manipulation

ƒ Read, write, create, delete, etc

ƒ Communications

ƒ Intra-processor or inter-processor communication – shared memory or message passing

(8)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Operation-System Services

ƒ Error Detection

ƒ Possible errors from CPU, memory, devices, user programs Æ Ensure correct & consistent computing

ƒ Resource Allocation

ƒ Utilization & efficiency

ƒ Accounting

ƒ Protection & Security

• user convenience or system efficiency!

Operation-System Services

ƒ System calls

ƒ Interface between processes & OS

ƒ How to make system calls?

ƒ Assemble-language instructions or subroutine/functions calls in high-level language such as C or Perl?

ƒGeneration of in-line instructions or a call to a special run-time routine.

ƒ Example: read and copy of a file!

ƒ Library Calls vs System Calls

(9)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Operation-System Services

ƒ How a system call occurs?

ƒ Types and information

ƒ Parameter Passing

ƒ Registers

ƒ Registers pointing to blocks

ƒ Linux

ƒ Stacks

x: parameters for call load address x system call 13

x

register

use parameters from table x

Code for System Call 13

Operation-System Services

ƒ System Calls

ƒ Process Control

ƒ File Management

ƒ Device Management

ƒ Information Maintenance

ƒ Communications

(10)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Operation-System Services

ƒ Process & Job Control

ƒ End (normal exit) or abort (abnormal)

ƒ Error level or no

ƒ Load and execute

ƒ How to return control?

ƒ e.g., shell load & execute commands

ƒ Creation and/or termination of processes

ƒ Multiprogramming?

Operation-System Services

ƒ Process & Job Control (continued)

ƒ Process Control

ƒ Get or set attributes of processes

ƒ Wait for a specified amount of time or an event

ƒ Signal event

ƒ Memory dumping, profiling, tracing, memory allocation & de-allocation

(11)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Operation-System Services

ƒ Examples: MS-DOS & UNIX

kernel command interpreter process free memory

kernel interpreter

process B free memory

process A

Operation-System Services

ƒ File Management

ƒ Create and delete

ƒ Open and close

ƒ Read, write, and reposition (e.g., rewinding)

ƒ lseek

ƒ Get or set attributes of files

ƒ Operations for directories

(12)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Operation-System Services

ƒ Device management

ƒ Request or release

ƒ Open and close of special files

ƒ Files are abstract or virtual devices.

ƒ Read, write, and reposition (e.g., rewinding)

ƒ Get or set file attributes

ƒ Logically attach or detach devices

Operation-System Services

ƒ Information maintenance

ƒ Get or set date or time

ƒ Get or set system data, such as the amount of free memory

ƒ Communication

ƒ Message Passing

ƒ Open, close, accept connections

ƒ Host ID or process ID

ƒ Send and receive messages

ƒ Transfer status information

ƒ Shared Memory

ƒ Memory mapping & process synchronization

(13)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Operation-System Services

ƒ Shared Memory

ƒ Max Speed & Comm Convenience

ƒ Message Passing

ƒ No Access Conflict & Easy Implementation

kernel Process A Process B

kernel Process A Process B

Shared Memory

M M M

System Programs

ƒ Goal:

ƒ Provide a convenient environment for program development and execution

ƒ Types

ƒ File Management, e.g., rm.

ƒ Status information, e.g., date.

ƒ File Modifications, e.g., editors.

ƒ Program Loading and Executions, e.g., loader.

ƒ Communications, e.g., telnet.

(14)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Programs – Command Interpreter

ƒ Two approaches:

ƒ Contain codes to execute commands

ƒFast but the interpreter tends to be big!

ƒPainful in revision!

del cd

System Programs – Command Interpreter

ƒ Implement commands as system programs Æ Search exec files which corresponds to commands (UNIX)

ƒ Issues

a. Parameter Passing

ƒ Potential Hazard: virtual memory b. Being Slow

c. Inconsistent Interpretation of Parameters

(15)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Structure – MS-DOS

ƒ MS-DOS Layer Structure

Application program

Resident system program

MS-DOS device drivers

ROM BIOS device drivers

System Structure – UNIX

terminal controller, terminals, physical memory, device controller, devices such as disks, memory, etc.

CPU scheduling, signal handling, virtual memory, paging, swapping,

file system, disk drivers, caching/buffering, etc.

Shells, compilers, X, application programs, etc.

UNIX Kernel interface

to the hardware System call interface

useruser user useruser user User user

interface

(16)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Structure

ƒ A Layered Approach – A Myth

Advantage: Modularity ~ Debugging &

Verification

Difficulty: Appropriate layer definitions, less efficiency due to overheads!

Layer M Layer M-1

hidden ops new

ops

existing ops

System Structure

ƒ A Layer Definition Example:

L5 User programs L4 I/O buffering

L3 Operator-console device driver L2 Memory management

L1 CPU scheduling L0 Hardware

(17)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Structure – OS/2

ƒOS/2 Layer Structure

Application Application Application

Subsystem Subsystem Subsystem

Device driver Device driver Device driver Application-program Interface

•memory management

System kernel •task scheduling

•device management

* Some layers of NT were from user space to kernel space in NT4.0

System Structure – Microkernels

ƒ The concept of microkernels was

proposed in CMU in mid 1980s (Mach).

ƒ Moving all nonessential components from the kernel to the user or system programs!

ƒ No consensus on services in kernel

ƒ Mostly on process and memory management and communication

ƒ Benefits:

ƒ Ease of OS service extensions Æ portability, reliability, secutrity

(18)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Structure – Microkernels

ƒ Examples

ƒ Microkernels: True64UNIX (Mach kernel), MacOS X (Mach kernel), QNX (msg passing, proc scheduling, HW interrupts, low-level networking)

ƒ Hybrid structures: Windows NT

kernel

OS/2

Applications OS/2 Server

POSIX

Applications POSIX Server Win32

Applications Win32 Server

Virtual Machine

ƒ Virtual Machines: provide an interface that is identical to the underlying bare hardware

interface

processes processes processes processes

kernel kernel kernel

hardware

virtual machine implementation hardware

kernel

VM1 VM2 VM3

(19)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Virtual Machine

ƒ Implementation Issues:

ƒ Emulation of Physical Devices

ƒ E.g., Disk Systems

ƒ An IBM minidisk approach

ƒ User/Monitor Modes

ƒ(Physical) Monitor Mode

ƒ Virtual machine software

ƒ(Physical) User Mode

ƒ Virtual monitor mode & Virtual user mode

Virtual Machine

virtual user mode virtual monitor mode monitor mode

processes processes processes

kernel 1 kernel 2 kernel 3

virtual machine software hardware

P1/VM1 system call

Trap

Service for the system call

Set program counter

& register contents,

& then restart VM1

Simulate the effect of the I/O instruction

Restart VM1 Finish service

time

(20)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Virtual Machine

ƒ Disadvantages:

ƒ Slow!

ƒ Execute most instructions directly on the hardware

ƒ No direct sharing of resources

ƒPhysical devices and communications

* I/O could be slow (interpreted) or fast (spooling)

Virtual Machine

ƒ Advantages:

ƒ Complete Protection – Complete Isolation!

ƒ OS Research & Development

ƒ System Development Time

ƒ Extensions to Multiple Personalities, such as Mach (software emulation)

ƒEmulations of Machines and OS’s, e.g., Windows over Linux

(21)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

Virtual Machine – Java

ƒ Sun Microsystems in late 1995

ƒ Java Language and API Library

ƒ Java Virtual Machine (JVM)

ƒClass loader (for bytecode .class files)

ƒClass verifier

ƒJava interpreter

ƒAn interpreter, a just-in-time (JIT) compiler, hardware

class loader verifier java interpreter

host system

java .class files

Virtual Machine – Java

ƒ JVM

ƒ Garbage collection

ƒ Reclaim unused objects

ƒ Implementation being specific for different systems

ƒ Programs are architecture neutral and portable

class loader verifier java interpreter

host system

java .class files

(22)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Design &

Implementation

ƒ Design Goals & Specifications:

ƒ User Goals, e.g., ease of use

ƒ System Goals, e.g., reliable

ƒ Rule 1: Separation of Policy & Mechanism

ƒ Policy:What will be done?

ƒ Mechanism:How to do things?

ƒ Example: timer construct and time slice

ƒ Two extreme cases:

Microkernel-based OS Macintosh OS

System Design &

Implementation

ƒ OS Implementation in High-Level Languages

ƒ E.g., UNIX, OS/2, MS NT, etc.

ƒ Advantages:

ƒ Being easy to understand & debug

ƒ Being written fast, more compact, and portable

ƒ Disadvantages:

ƒ Less efficient but more storage for code

(23)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.

System Generation

ƒ SYSGEN (System Generation)

ƒ Ask and probe for information concerning the specific configuration of a hardware system

ƒ CPU, memory, device, OS options, etc.

No recompilation Recompilation

& completely Linking of of a modified table-driven modules for source code

selected OS

ƒ Issues

ƒ Size, Generality, Ease of modification

參考文獻

相關文件

 civilian life and opportunities ©2011 Yen-Ping Shan All rights reserved

4 理律法律事務所 © 2020 All rights

All rights reserved.. 1

Project 1.3 Use parametric bootstrap and nonparametric bootstrap to approximate the dis- tribution of median based on a data with sam- ple size 20 from a standard normal

All rights reserved.... All

* All rights reserved, Tei-Wei Kuo, National Taiwan University,

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005..

* All rights reserved, Tei-Wei Kuo, National Taiwan University,