chapter 1 (part 2) operating system concepts department of computer science southern illinois...

27
Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki E-mail: [email protected] S 314 Operating Systems Chapter_One_2/001

Upload: doris-sparks

Post on 17-Jan-2018

224 views

Category:

Documents


0 download

DESCRIPTION

Chapter_One/003 Subjects covered about “process” What is “process”? How is it different from “program”? What we can do by “processes”? A: “Process” is a program in execution. HDD “program” is an executable file stored in a disk program Stored as a file Q: What is “process”? Solutions CS 314 Operating Systems

TRANSCRIPT

Page 1: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter 1 (PART 2) Operating System Concepts

Department of Computer ScienceSouthern Illinois University Edwardsville

Spring, 2016

Dr. Hiroshi FujinokiE-mail: [email protected]

CS 314 Operating Systems

Chapter_One_2/001

Page 2: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/002

Operating System Concepts

This PPT presentation covers Section 1.5 of the textbook.

(1) Process

(2) Deadlock avoidance in I/O resource management

(3) Files and file descriptor

(4) Special Files

CS 314 Operating Systems

Page 3: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/003

Subjects covered about “process”

• What is “process”?

• How is it different from “program”?

• What we can do by “processes”?

A: “Process” is a program in execution.

HDD

“program” is an executablefile stored in a disk

program

Stored as a file

Q: What is “process”?

Solutions

CS 314 Operating Systems

Page 4: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/004

Then how a “program” can become “process”?

HDD

program

Stored as a file

Memory

CPU

A program becomes a processwhen one is loaded into the memory for execution by CPU

Load

CS 314 Operating Systems

Page 5: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/005

Things needed for a program to be executed in memory

Memory

HDD

Program Code Stack Memory

Heap Memory

AddressSpace

Program X

Program Z

CPU

PCB-Z PCB-A PCB-X

PCB = Process Control Block

PCB is a data structure for the CPUto keep track of each process

Process

Program

CS 314 Operating Systems

Page 6: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/006

Example of “program” and “process”

• Program

• Process

Static object, usually exists as an executable file

Program in execution

This is a program

This is a process (program in execution)

CS 314 Operating Systems

Page 7: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/007

Intermediate summary of “process”

• It is a program in execution

• A process consists of the contents in process address space and PCB

• Process address space consists of:

Program Code

Stack Memory Space

Heap Memory Space

Collection of assembly instructions CPU runs

Stack data structure for sub-routine calls

Other data structure (local/global variables)

Questions

Where are PCBs located?

What information does PCB hold?

CS 314 Operating Systems

Page 8: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/008

Things needed for a program to be executed in memory

Memory

Program X

Program Z

CPU

PCB-Z PCB-A PCB-X

Program Y

OS

Where are PCBs located?

In the operating system

CS 314 Operating Systems

Page 9: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/009

Operating System Structure

Monolithic Structure

VM (Virtual Machine)

Micro-KernelWindows uses these concepts

This PPT presentation covers Section 1.7 of the textbook.

CS 314 Operating Systems

Page 10: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/010

Monolithic Structure OS

• Operating systems are essentially a collection of procedures.

Monolithic Structure OS No structure in a collection of procedures

(Any procedure or a user application can call any other procedure)

OS Procedures

Disk I/O

Process Mgmt.

Memory Mgmt.

Printer Spooler

IPC

KB I/O

user

Program

• Big mess

• But fast (no overhead)

CS 314 Operating Systems

Page 11: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/011

How is a Monolithic-Structured OS implemented?

OS Procedures

Disk I/O

Process Mgmt.

Memory Mgmt.

Printer Spooler

IPCKB I/O

Disk I/O

Memory Mgmt.

Process Mgmt.

IPC

KB I/O

Printer Spooler

Source codemodules

Concatenate intoone source code file

Compile

OS

Operating system as an executable program

CS 314 Operating Systems

Page 12: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

“OS” in a broader definition

Chapter_One/012

How is a Monolithic-Structured OS implemented?

OS

Operating system as an executable program

awk

grep

sort

Disk I/O

Memory Mgmt.

Process Mgmt.

IPC

KB I/O

Printer Spooler

Program

System calls

External Commands

user

execute

exec ();

“OS Kernel”

CS 314 Operating Systems

Page 13: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/013

Virtual Machine (VM)

Without VM

HardwareOperating System

App1 App N

user

OS1

Virtual Machine SupportOS2 OS3

A virtual machine

UNIX Windows 2000

Application programs

Hardware

With VM

MS-DOS

Extra layer ontop of hardware

CS 314 Operating Systems

Page 14: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/014

Hardware

OS1

Virtual Machine SupportOS2 OS3

Hardware1

OS2 OS3

OS1

Hardware2 Hardware3

Concept of VM

For each application program,it looks like they are beingexecuted by the dedicated

hardware

CS 314 Operating Systems

Page 15: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/015

Without VM

Memory

Process X

Process Y

Process Z

OS

With VM

Memory

OS1

OS3

OS2

Process X

Process Y

VMS

VM1

VM2

VM3

ProcessManage

ProcessManage

Process M

Process NProcessManage

Process A

Process BProcessManage

VMManage

Implementation of of VM

CS 314 Operating Systems

Page 16: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/016

Summary of Virtual Machine (VM)

VM A virtual computer where computer hardware is software-emulatedby VMS (Virtual Machine Support)

• Provide virtual dedicated machine (= hardware) to each OS

Multiple operating systems (and its applications) at once

(Q: What’s the difference from “multiple boot”?)

- For flexibility

- For robustness

One VM crashes, others still survive(EG: Windows-NT)

CS 314 Operating Systems

Page 17: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

“OS” in a broader definition

Chapter_One/017

OS

awk

grep

sort

Disk I/O

Memory Mgmt.

Process Mgmt.

IPC

KB I/O

Printer Spooler

External Commands

“OS Kernel”

Micro-Kernel Architecture

CS 314 Operating Systems

Page 18: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

“OS” in a broader definition

Chapter_One/018

awk

grep

sort

Disk I/O

IPC

KB I/O

Memory Mgmt.

Process Mgmt.

Printer Spooler

External Commands

OS

“OS Kernel”

Micro-Kernel Architecture (continued)

Memory Mgmt.

Process Mgmt.

Printer Spooler

CS 314 Operating Systems

Page 19: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/019

Micro-Kernel Architecture (continued)

Computer Hardware

Operating System

User Program

User-Mode

Kernel-Mode

In ordinary OS (not Micro-Kernel OS), OS has to provideall the user services in Kernel-mode services

OS kernel tends to be huge

System Call

OS Procedure (in the OS kernel)

CS 314 Operating Systems

Page 20: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/020

Micro-Kernel Architecture (continued)

Computer Hardware

Operating System

User Program

User-Mode

Kernel-Mode

Spooler

Micro-Kernel Architecture is based on Client-Server Model

Client Server

Micro-kernel Architecture Make the OS kernel as small as possible

Operating System becomes a service broker

CS 314 Operating Systems

Page 21: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/021

Micro-Kernel Architecture (continued)

What is it good for?

MS Windows uses micro-kernel architecture for this reason

(1) Each OS function becomes a module

A bug in OS can be fixed by replacing a module

(what we should do if “monolithic structure kernel”?)

(2) Better robustness

OS functions may be executed in user-mode

(a bug in a module will not crash the kernel)

CS 314 Operating Systems

Page 22: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Deadlock

Chapter_One/022

Deadlock avoidance in I/O resource management

What is “deadlock”?

More than one process wait for resource for each other for forever

Example

Resources

Printer

HDD

• Assume that there are two processes• Each of the two processes requires printer and HDD at the same time• Without the printer and HDD, neither can finish its tasks

Process AProcess B

Assigned

Assignedwait

wait

(Circular-wait)

CS 314 Operating Systems

Page 23: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/023

Concept of files and file descriptor

Logical data storages in computer systems

What is a file?

What is “file descriptor”?

Logical identification for each file being usedin a computer system.

HDD

file

OSuser

open read

load

use

close

CS 314 Operating Systems

Page 24: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Concept of files and file descriptor (continued)

A

BX

Y

File Names

“A.txt”

User

HDDOS

Location on disk

• Sectors• Track• Platters

Open “A.txt”

Find/Access

LoadFile Descriptor

• Read (FD)• Write (FD)• Append (FD)

File Names Sector Locations

File Allocation Table

Chapter_One/024

A.txt 1E23CD

CS 314 Operating Systems

Page 25: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/025

Concept of Special Files

Ordinary File

user

OS

HDD

file

Can not be seenby human user

user

OS

HDD

Special Files

Keyboard

Users can I/O tomany devices as if they

were a file

ModemInternet

RequestRequest (1)

Response (4)Internet

Request

Network

Special Files

CS 314 Operating Systems

printer

Page 26: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

user

OS

HDD

Printer (LPT)

Keyboard (KB)

fd = open (my_text, READ_WRITE);write (fd, out_buffer);read (fd, in_buffer);close (fd);

fd = open (LPT, WRITE);write (fd, out_buffer);close (fd);

fd = open (KB, READ);read (fd, in_buffer);close (fd);

Can not be seenby human user

Chapter_One/026

Concept of Special Files

CS 314 Operating Systems

file

file

file

Page 27: Chapter 1 (PART 2) Operating System Concepts Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Chapter_One/027

Special Files

A concept in OS where a user can handle many different I/O devicesusing the same interface (APIs) that is used for actual files.

• When you open (reserve) a resource, OS gives you “descriptor”

• Some special files are read-only and some others may be write-only

Read-OnlyRead/Write Write-Only

- Disks - Keyboard - Printer

- Network - Mouse

- CRT Monitor (with touch-pen support)

- CD-ROM- CRT Monitor

CS 314 Operating Systems