Operating Systems CS 217. Provides each process with a virtual machine. Promises each program the illusion of having whole machine to itself

Similar documents
What Is Operating System? Operating Systems, System Calls, and Buffered I/O. Academic Computers in 1983 and Operating System

Goals of this Lecture

I/O Management! Goals of this Lecture!

I/O Management! Goals of this Lecture!

CS 126 Lecture S4: Operating Systems

Process Management! Goals of this Lecture!

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 5460/6460 Operating Systems

Basic Computer Hardware

W4118: OS Overview. Junfeng Yang

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

OPERATING SYSTEM OVERVIEW

CSC 2405: Computer Systems II

Last class: Today: Course administration OS definition, some history. Background on Computer Architecture

Computer-System Architecture (cont.) Symmetrically Constructed Clusters (cont.) Advantages: 1. Greater computational power by running applications

What is an Operating System? A Whirlwind Tour of Operating Systems. How did OS evolve? How did OS evolve?

hardware interrupts software interrupts

CS330: Operating System and Lab. (Spring 2006) I/O Systems

! Software ( kernel ) that runs at all times. ! OS performs two unrelated functions: Maria Hybinette, UGA. user! 1! Maria Hybinette, UGA. user! n!

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

CS450/550 Operating Systems

Computer Systems II. First Two Major Computer System Evolution Steps

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Systems Programming. 08. Standard I/O Library. Alexander Holupirek

CSCI 6730 / 4730 Operating Systems. Key Questions in System Design. Review: What is An Operating System? Key Points

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

Operating Systems. V. Input / Output

CS350 Operating Systems

Introduction. CS3026 Operating Systems Lecture 01

Hardware OS & OS- Application interface

CSE 509: Computer Security

10. I/O System Library

Layers in a UNIX System. Create a new process. Processes in UNIX. fildescriptors streams pipe(2) labinstructions

Instruction Cycle. Computer-System Architecture. Computer-System Operation. Common Functions of Interrupts. Chapter 2: Computer-System Structures

Operating Systems CS 571

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

I/O Systems. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS 537 Lecture 2 Computer Architecture and Operating Systems. OS Tasks

Processes COMPSCI 386

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Objectives. Chapter 2: Operating-System Structures. 2.1 Operating System Services

The course that gives CMU its Zip! I/O Nov 15, 2001

System-Level I/O. Topics Unix I/O Robust reading and writing Reading file metadata Sharing files I/O redirection Standard I/O

File. File System Implementation. File Metadata. File System Implementation. Direct Memory Access Cont. Hardware background: Direct Memory Access

CSE 333 SECTION 3. POSIX I/O Functions

Process Scheduling Queues

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Outline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra

Architectural Support for Operating Systems

Architectural Support for OS

File I/O. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Administrivia. CS140 Operating Systems. Lecture videos. Administrivia 2. Course goals. Course topics. Class web page:

Four Components of a Computer System

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

I/O Systems. Jo, Heeseung

CPS221 Lecture: Operating System Protection

OS Structure. Hardware protection & privilege levels Control transfer to and from the operating system

Operating Systems. Introduction & Overview. Outline for today s lecture. Administrivia. ITS 225: Operating Systems. Lecture 1

ELEC 377 Operating Systems. Week 1 Class 2

Operating Systems ( )

Announcement. Exercise #2 will be out today. Due date is next Monday

Chap.6 Limited Direct Execution. Dongkun Shin, SKKU

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

Processes, Context Switching, and Scheduling. Kevin Webb Swarthmore College January 30, 2018

CS140 Operating Systems

Operating Systems: Principles and Practice. Mark Zbikowski Gary Kimura (kudos to Tom Anderson)

Module 2: Computer-System Structures. Computer-System Architecture

Part I Overview Chapter 1: Introduction

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

Introduction to Computer Systems and Operating Systems

Operating System Services

CSci 4061 Introduction to Operating Systems. Input/Output: High-level

I/O. CS 416: Operating Systems Design Department of Computer Science Rutgers University

File Access. FILE * fopen(const char *name, const char * mode);

W4118: interrupt and system call. Junfeng Yang

EECS 3221 Operating System Fundamentals

EECS 3221 Operating System Fundamentals

Lecture 4: Memory Management & The Programming Interface

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song Spring 2015

Chapter 2: System Structures

CS510 Operating System Foundations. Jonathan Walpole

Lecture 15: I/O Devices & Drivers

Operating System Review

CS399 New Beginnings. Jonathan Walpole

CSCE-313 Introduction to Computer Systems

Chapter 1: Introduction

Unit 2 : Computer and Operating System Structure

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

Operating Systems and Protection CS 217

File. File System Implementation. Operations. Permissions and Data Layout. Storing and Accessing File Data. Opening a File

Naked C Lecture 6. File Operations and System Calls

OS structure. Process management. Major OS components. CSE 451: Operating Systems Spring Module 3 Operating System Components and Structure

Module 1: Introduction

- All assignments, handouts, lecture notes on-line

Input and Output System Calls

Computer System Overview

CSE 153 Design of Operating Systems Fall 18

Operating Systems ( )

Transcription:

Operating Systems CS 217 Operating System (OS) Provides each process with a virtual machine Promises each program the illusion of having whole machine to itself Process Process Process Process OS Kernel Hardware 1

Operating System Coordinates access to physical resources CPU, memory, disk, i/o devices, etc. Provides services Protection Scheduling Memory management File systems Synchronization etc. Process OS Kernel Process Hardware OS as Government Makes lives easy Promises everyone whole machine (dedicated CPU, infinite memory, ) Provides standardized services (standard libraries, window systems, ) Makes lives fair Arbitrates competing resource demands Makes lives safe Prevent accidental or malicious damage by one program to another 2

OS History Development of OS paradigms: Phase 0: at console Phase 1: Batch processing Phase 2: Interactive time-sharing Phase 3: Personal computing Phase 4:? Computing price/performance affects OS paradigm Phase 0: at Console How things work One program running at a time No OS, just a sign-up sheet for reservations Each user has complete control of machine Advantages Interactive! No one can hurt anyone else Disadvantages Reservations not accurate, leads to inefficiency Loading/ unloading tapes and cards takes forever and leaves the machine idle 3

Phase 1: Batch Processing How things work Sort jobs and batch those with similar needs to reduce unnecessary setup time Resident monitor provides automatic job sequencing : it interprets control cards to automatically run a bunch of programs without human intervention Advantage Good utilization of machine Disadvantagess Loss of interactivity (unsolvable) One job can screw up other jobs, need protection (solvable) Good for expensive hardware and cheap humans Phase 2: Interactive Time-Sharing How things work Multiple users per single machine OS with multiprogramming and memory protection Advantages: Interactivity Sharing of resources Disadvantages: Does not always provide reasonable response time Good for cheap hardware and expensive humans 4

Phase 3: Personal Computing How things work One machine per person OS with multiprogramming and memory protection Advantages: Interactivity Good response times Disadvantages: Sharing is harder Good for very cheap hardware and expensive humans Phase 4: What Next? How will things work? Many machines per person? Ubiquitous computing? What type of OS? Good for very, very cheap hardware and expensive humans 5

Layers of Abstraction process Appl Prog Stdio Library FILE * stream Kernel File System Storage Driver hierarchical file system variable-length segments disk blocks Disk System Calls Processor modes user mode: can execute normal instructions and access only user memory supervisor mode: can also execute privileged instructions and access all of memory (e.g., devices) System calls user cannot execute privileged instructions users must ask OS to execute them - system calls system calls are often implemented using traps OS gains control through trap, switches to supervisor model, performs service, switches back to user mode, and gives control back to user 6

System Calls Method by which user processes invoke kernel services: protected procedure call user kernel Appl Prog Stdio Library File System fopen,fclose, printf, fgetc, getchar, open, close, read, write, seek Unix has ~150 system calls; see man 2 intro /usr/include/syscall.h Interrupt-Driven Operation Everything OS does is interrupt-driven System calls use traps to interrupt An interrupt stops the execution dead in its tracks, control is transferred to the OS Saves the current execution context in memory (PC, registers, etc.) Figures out what caused the interrupt Executes a piece of code (interrupt handler) Re-loads execution context when done, and resumes execution 7

Interrupt Processing System Calls (cont) Parameters passed in fixed registers in fixed memory locations in an argument block, w/ block s address in a register on the stack Usually invoke system calls with trap instructions ta 0 with parameters in %g1 (function), %o0..%o5, and on the stack Mechanism is highly machine-dependent 8

Read System Call Read call nread = read(fd, buffer, n); Reads n bytes from fd into buffer returns number of bytes read, or 1 if there s an error In the caller mov fd,%o0 mov buffer,%o1 mov n,%o2 call read; nop mov %o0,nread Read System Call (cont) -side implementation (libc) read: set 3,%g1 ta 0 bcc L1; nop set _errno,%g1 st %o0,[%g1] set 1,%o0 L1: retl; nop Kernel-side implementation sets the C bit if an error occurred stores an error code in %o0 (see /usr/include/sys/errno.h) 9

Write System Call int safe_write(int fd, char *buf, int nbytes) { int n; char *p = buf; char *q = buf + nbytes; while (p < q) { if ((n = write(fd, p, q-p)) > 0) p += n; else perror( safe_write: ); } return nbytes; } Buffered I/O Single-character I/O is usually too slow int getchar(void) { char c; if (read(0, &c, 1) == 1) return c; return EOF; } 10

Buffered I/O (cont) Solution: read a chunk and dole out as needed int getchar(void) { static char buf[1024]; static char *p; static int n = 0; if (n--) return *p++; } n = read(0, buf, sizeof(buf)); if (n <= 0) return EOF; n = 0; p = buf; return getchar(); Standard I/O Library #define getc(p) (--(p)->_cnt >= 0? \ (int)(*(unsigned char *)(p)->_ptr++) : \ _filbuf(p)) typedef struct _iobuf { int _cnt; /* num chars left in buffer */ char *_ptr; /* ptr to next char in buffer */ char *_base; /* beginning of buffer */ int _bufsize;/* size of buffer */ short _flag; /* open mode flags, etc. */ char _file; /* associated file descriptor */ } FILE; extern FILE *stdin, *stdout, *stderr; 11

Summary OS virtualizes machine Provides each process with illusion of having whole machine to itself OS provides services Protection Sharing of resources Memory management File systems etc. Protection achieved through separate kernel processes uses system calls to ask kernel to access protected stuff on its behalf 12