Introduction to Computer Science. Polly Huang NTU EE

Similar documents
Chapter 3. Operating Systems Pearson Addison-Wesley. All rights reserved

The functionality. Managing more than Operating

OPERATING SYSTEMS. COMS W1001 Introduction to Information Science. Boyi Xie

CSCI 120 Introduction to Computation Operating System (draft)

OPERATING SYSTEM. Functions of Operating System:

Multiprogramming. Evolution of OS. Today. Comp 104: Operating Systems Concepts 28/01/2013. Processes Management Scheduling & Resource Allocation

Module 1. Introduction:

Operating Systems Overview. Chapter 2

QUESTION BANK UNIT I

Download from Powered By JbigDeaL

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

9/14/2010. Chapter 3: Software Overview. Types of Software. Functions of Operating Systems. Software classification

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

ROEVER ENGINEERING COLLEGE, PERAMBALUR DEPARTMENT OF INFORMATION TECHNOLOGY OPERATING SYSTEMS QUESTION BANK UNIT-I

SNS COLLEGE OF ENGINEERING

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

Chapter 3. Deadlocks

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

Chapter 13: I/O Systems

Deadlocks. Thomas Plagemann. With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT I

CLASS: II YEAR / IV SEMESTER CSE SUBJECT CODE AND NAME: CS6401 OPERATING SYSTEMS UNIT I OPERATING SYSTEMS OVERVIEW

OPERATING SYSTEM. PREPARED BY : DHAVAL R. PATEL Page 1. Q.1 Explain Memory

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

Lecture 12 2/19/04 13:43. Lecture 12. Operating Systems (S&G, 6.4) 2/19/04 CS Lecture Read S&G ch. 7, 7.1

COSC243 Part 2: Operating Systems

CS6401- OPERATING SYSTEM

Some popular Operating Systems include Linux Operating System, Windows Operating System, VMS, OS/400, AIX, z/os, etc.

To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Operating Systems Overview. Chapter 2

Main Points of the Computer Organization and System Software Module

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Operating System Third Year CSE( Sem:I) 2 marks Questions and Answers UNIT I

Chapter 1: Introduction

Operating System Review Part

CHAPTER NO - 1 : Introduction:

Following are a few basic questions that cover the essentials of OS:

Chapter 3. Deadlocks

Operating System. Operating System Overview. Layers of Computer System. Operating System Objectives. Services Provided by the Operating System

Operating System Overview. Operating System

General Objectives: To understand the process management in operating system. Specific Objectives: At the end of the unit you should be able to:

Basic functions in operating systems

AMSC/CMSC 662 Computer Organization and Programming for Scientific Computing Fall 2011 Operating Systems Dianne P. O Leary c 2011

Operating Systems. Lecture3.2 - Deadlock Management. Golestan University. Hossein Momeni

Chapter 1: Introduction

Resources. Lecture 4. Deadlocks. Resources (2) Resources (1) Four Conditions for Deadlock. Introduction to Deadlocks

7/20/2008. What Operating Systems Do Computer-System Organization

CS370 Operating Systems

Operating Systemss and Multicore Programming (1DT089)

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

UNIT I OPERATING SYSTEMS OVERVIEW

Major Requirements of an OS

Chapter 1: Introduction. Chapter 1: Introduction

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

CS370 Operating Systems

Process Description and Control. Chapter 3

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Deadlocks. Tore Larsen. With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen

Mon Sep 17, 2007 Lecture 3: Process Management

Fundamentals of Operating Systems (COMP355/L) A Student's Manual for Practice Exercises

Operating System. Operating System Overview. Structure of a Computer System. Structure of a Computer System. Structure of a Computer System

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Unit 3 : Process Management

Introduction. CS3026 Operating Systems Lecture 01

CS420: Operating Systems

MODERN OPERATING SYSTEMS. Third Edition ANDREW S. TANENBAUM. Chapter 6 Deadlocks

OPERATING SYSTEMS: Lesson 1: Introduction to Operating Systems

CS420: Operating Systems

UNIT I PROCESSES AND THREADS

Computer System Overview

SAZ4B/SAE5A Operating System Unit : I - V

CSC 453 Operating Systems

CSE 4/521 Introduction to Operating Systems. Lecture 27 (Final Exam Review) Summer 2018

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

Chapter 1: Introduction. Operating System Concepts 9 th Edit9on

Operating System Support

Introduction. What is an Operating System? A Modern Computer System. Computer System Components. What is an Operating System?

Operating Systems: (Tue)

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Chapter 1: Introduction

Part I Overview Chapter 1: Introduction

Major OS Achievements. Chris Collins. 15 th October 2006

Technology in Action. Chapter 5 System Software: The Operating System, Utility Programs, and File Management

Unit 2 : Computer and Operating System Structure

Chapter 3: Deadlocks

Chapter 3 Memory Management: Virtual Memory

Comp 204: Computer Systems and Their Implementation. Lecture 9: Deadlock

Virtual Memory Outline

CS450/550 Operating Systems

Dr. Andrea Bracciali, Room 4B86,

Chap. 3. Input/Output

Operating Systems : Overview

Chapter 14 Operating Systems

Some popular Operating Systems include Linux, Unix, Windows, MS-DOS, Android, etc.

Chapter 14 Operating Systems

European University of Lefke. Instructor: Dr. Arif SARI

OPERATING SYSTEM SUPPORT (Part 1)

CSI3131 Final Exam Review

DEADLOCKS M O D E R N O P E R A T I N G S Y S T E M S C H A P T E R 6 S P R I N G

Computer Fundamentals : Pradeep K. Sinha& Priti Sinha

Operating Systems: Internals and Design Principles. Chapter 2 Operating System Overview Seventh Edition By William Stallings

Transcription:

Introduction to Computer Science Polly Huang NTU EE http://homepage.ntu.edu.tw/~pollyhuang pollyhuang@ntu.edu.tw Polly Huang, NTU EE Operating System 1 Chapter 3 Operating Systems Polly Huang, NTU EE Operating System 2 1

Chapter 3 Operating Systems 3.1 The Evolution of Operating Systems 3.2 Operating System Architecture 3.3 Coordinating the Machine s Activities 3.4 Handling Competition Among Processes 3.5 Security Polly Huang, NTU EE Operating System 3 Operating Systems Interface between a user and the computer hardware Provide an environment in which a user can execute programs Goals Make the computer system convenient to use Use the computer hardware (resources) in an efficient manner Polly Huang, NTU EE Operating System 4 2

Some Functions of OS Oversee/control/monitor operation of computer Store and retrieve files/programs Schedule programs for execution Execute programs Polly Huang, NTU EE Operating System 5 A Few Notions Batch processing Interactive processing Real-time processing Time-sharing system Multiprocessor system Polly Huang, NTU EE Operating System 6 3

Batch Processing Polly Huang, NTU EE Operating System 7 Interactive Processing Polly Huang, NTU EE Operating System 8 4

Real-Time Processing Processing where the response time is restricted For example, to operate the missile launching systems Polly Huang, NTU EE Operating System 9 Time-Sharing Systems Shuffle jobs by dividing time into intervals Multitasking for a one-user system More efficient than the sequential way especially for jobs which must wait for peripheral devices For example, to operate PCs with lots of I/O peripherals Polly Huang, NTU EE Operating System 10 5

Time Sharing at Home You have one PC at home You, your sister, your dad, your mom, the grandma and grandpa share the PC During the 7pm-10pm hours, everyone might need the PC at a random time Design two different ways of sharing the PC time among the users and state why the choice In other words: Who gets the PC from when and for how long? And why you think your mechanisms are reasonable? Polly Huang, NTU EE Operating System 11 Multiprocessor Systems Sharing information and resources among different machines Networks (next chapter) To couple computer systems Software controlling a network as a network-wide operating system Polly Huang, NTU EE Operating System 12 6

Unique Problems Load balancing Dynamically allocate tasks to various processors so that all processors are used efficiently Scaling Break tasks into a number of subtasks compatible with the number of processors available Hopefully, N processors à N times throughput Polly Huang, NTU EE Operating System 13 Chapter 3 Operating Systems 3.1 The Evolution of Operating Systems 3.2 Operating System Architecture 3.3 Coordinating the Machine s Activities 3.4 Handling Competition Among Processes 3.5 Security Polly Huang, NTU EE Operating System 14 7

Types of software Application software Perform specific tasks for users System software Perform tasks needed by all computer systems Operating system Utility software Collection of software units extending the capabilities of OS Polly Huang, NTU EE Operating System 15 Law and Orders, Technologically Speaking Internet Explorer Application software? Utility software? Internet Explorer comes with Windows Unfair competition? Better OS? Polly Huang, NTU EE Operating System 16 8

Software Classification Polly Huang, NTU EE Operating System 17 Shell: the User-OS Interface Polly Huang, NTU EE Operating System 18 9

Shells Portion of an OS Define the interface between the OS and its users Types of shells Textual interface Borne shell, C shell, Korn shell in Unix MS-DOS command line for Microsoft Windows Graphical user interface Window manager in Unix WinXP, Mac Polly Huang, NTU EE Operating System 19 Kernels Performs the very basic functions required by the computer installation Main components File manager Device drivers Memory manager Scheduler and dispatcher Polly Huang, NTU EE Operating System 20 10

File Manager Polly Huang, NTU EE Operating System 21 File System Directory or folder User-created group or bundle of files Path: position of a file in directory hierarchy C:\animals\prehistoric\dinosaurs Any access to a file by other software units is obtained with the help of the file manager File descriptor: information needed to access an open file Polly Huang, NTU EE Operating System 22 11

Device Manager Polly Huang, NTU EE Operating System 23 Device Driver Software units that 1. tightly coupled with the controllers 2. to carry out operations on the peripheral devices attached to the machine Each device driver is uniquely designed for its particular type of device Example: Device driver for a printer contains software to read and decode status word as well as other handshaking details. Other software does not have to deal with those details in order to print a file Polly Huang, NTU EE Operating System 24 12

Memory Manager Coordinating the machine s use of main memory Quite a lot of work in multi-user or timesharing environments Many programs and data reside in main memory concurrently Polly Huang, NTU EE Operating System 25 Three Major Functions When new programs/data are to be processed Must find memory area to fulfill the program/data s memory requirements While programs/data are in progress Need to know which memory cells belonging to which program/data When programs/data are finished with processing Need to keep track of memory areas no longer occupied Polly Huang, NTU EE Operating System 26 13

Easier Analogy Suppose you work part-time as the receptionist ( 領檯 ) of a restaurant Polly Huang, NTU EE Operating System 27 Quiz Time! Polly Huang, NTU EE Operating System 28 14

Memory Management Methods Partition Page Unit of memory managed A few kilobytes Virtual memory Illusionary memory space Useful when there s not enough RAM space for the programs/data to execute Polly Huang, NTU EE Operating System 29 Partitioning Divide memory into partitions Fixed-size partitions Variable-size partitions Polly Huang, NTU EE Operating System 30 15

Fixed-Size Partitioning What should be the size? Can t be too small The partition must accommodate the largest possible program Can t be too large May cause wasted memory space Polly Huang, NTU EE Operating System 31 Variable-size Partitioning Sequential memory allocation Program memory space interleaving Tedious link list Sequential memory block allocation Less memory space interweaving Manageable link list Memory blocks are referred to as page frames Polly Huang, NTU EE Operating System 32 16

Page Divide the program into equal-size pieces (pages) Store each piece in equal-size memory spaces (page frames) Typical size is 2KB or 4KB Create an index to each page and store in a Page Table Polly Huang, NTU EE Operating System 33 Comparison Manageability Fixed-size Partition Page Thrifty use of memory Variable-size Partition Run out of RAM space! Some parts of a program might not really be used Polly Huang, NTU EE Operating System 34 17

Virtual Memory Illusion of additional memory space by rotating pages of programs and data back and forth Between main memory (RAM) and mass storage (hard disk) Software units can execute as though there were a large amount of main memory in the machine Polly Huang, NTU EE Operating System 35 Paging A portion of the program is placed in memory (RAM) The remainder is on disk (hard disk) Pages on disk will be brought into memory as needed (one page at a time) Referred to as the Paging Process Polly Huang, NTU EE Operating System 36 18

Swapping If there s no free space on the physical memory, some pages need to be discarded This is referred to as the swapping process Polly Huang, NTU EE Operating System 37 Quiz Time! Polly Huang, NTU EE Operating System 38 19

Swapping Rule Oldest The oldest page gets swapped out first Least Frequently Used (LFU) The least used gets swapped out first Least Recently Used (LRU) The least recently used gets swapped out first Linux Polly Huang, NTU EE Operating System 39 LRU Exercise There is a running process on Linux and the physical memory space is only 4 page large. Suppose the process needs to load the pages in the following order: 1, 2, 3, 4, 5, 2, 6. Q: Which is the page to be replaced by page 5? Q: Which is the page to be replaced by page 2? Q: Which is the page to be replaced by page 6? Polly Huang, NTU EE Operating System 40 20

Thrashing Too large a portion of CPU time is spent locating the correct page and bringing it into memory Polly Huang, NTU EE Operating System 41 Thrashing Exercise In a LFU system where the physical memory space is only 4 page large. Suppose the process needs to load the pages in the following order: 1, 2, 3, 4, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5. Q: Which is the page to be replaced by each page load? If no page is swapped out, just write - Polly Huang, NTU EE Operating System 42 21

Linux Page-based Virtual Memory Demand Paging Least Recently Used Swapping Windows? you guess Polly Huang, NTU EE Operating System 43 Scheduler and Dispatcher Process manager! Scheduler Determines which activities are to be considered for execution in a time-sharing system Dispatcher Controls the allocation of time slices to the scheduled activities (how long) Polly Huang, NTU EE Operating System 44 22

Getting it Started (bootstrapping) Bootstrap: program in read only memory (ROM) Run by the CPU when power is turned on Basic Input Output System Transfers operating system from mass storage to main memory After OS installation, inform the BIOS the location Configurable via BIOS Executes jump to operating system At this point, the operating system takes over and begins controlling the machine s behavior Polly Huang, NTU EE Operating System 45 The Booting Process Polly Huang, NTU EE Operating System 46 23

Chapter 3 Operating Systems 3.1 The Evolution of Operating Systems 3.2 Operating System Architecture 3.3 Coordinating the Machine s Activities 3.4 Handling Competition Among Processes 3.5 Security Polly Huang, NTU EE Operating System 47 Processes Program A static set of directions Process Program (application and utilities) in execution Needs resources to accomplish its task Resources are given to the process when created Can be executed in parallel Polly Huang, NTU EE Operating System 48 24

Process Management Handled by scheduler and dispatcher within kernel Scheduler Maintains a process table Dispatcher Ensures the scheduled processes are actually executed Time slice (or quantum): typically no more than 50 milliseconds Process switch Polly Huang, NTU EE Operating System 49 Process Table Polly Huang, NTU EE Operating System 50 25

Scheduler Keeps states of all processes in a process table Scheduling information Status of processes Ready or waiting Priority of processes Non-scheduling information Memory pages assigned to the processes Process states Polly Huang, NTU EE Operating System 51 Process Status Defined by its current activity new ready running halted waiting Polly Huang, NTU EE Operating System 52 26

Process State A snapshot of the machine at that time Includes program counter, values in CPU registers and associated memory cells, etc. Changes as a process executes Polly Huang, NTU EE Operating System 53 Program and Processes Process Table Data Process State Process Priority Process Status Program Execution Code Polly Huang, NTU EE Operating System 54 27

Dispatcher Gives one time slice or quantum to a process that is ready Executes a process switch (or context switch) when the running process s time slice is over Interrupt indicates that time slice is over Interrupt generated Interrupt handled by interrupt handler interrupt handler is part of dispatcher Polly Huang, NTU EE Operating System 55 Interrupt Handler Process state of an executing process is saved and the process becomes idle Process state of the process to be executed next is loaded The new process starts running Polly Huang, NTU EE Operating System 56 28

Time-Sharing Between A & B Polly Huang, NTU EE Operating System 57 Chapter 3 Operating Systems 3.1 The Evolution of Operating Systems 3.2 Operating System Architecture 3.3 Coordinating the Machine s Activities 3.4 Handling Competition Among Processes 3.5 Security Polly Huang, NTU EE Operating System 58 29

Competition among Processes What could be the problem if two time-sharing processes are printing at the same time? Any easy solution? Polly Huang, NTU EE Operating System 59 Competition for Resources Assume a process needs to print Request the OS to give it access to the printer s device driver OS decide whether to grant the request, depending upon whether the printer is already being used by another process If the printer is used by another process, the OS should deny the request and classify the process as waiting until the printer is ready If two processes were given simultaneous access to printer, the results would be worthless to both!! Also known as the race condition Polly Huang, NTU EE Operating System 60 30

Allocation of Resources An important task of an operating system is the allocation of resources to the processes in the system How to allocate is resource dependent! Resources: machine s peripheral devices as well as features within the machine Access to files and disk space (file manager) Memory space (memory manager) Space in process table (scheduler) Time slices (dispatcher) Polly Huang, NTU EE Operating System 61 Using Flag to Control Access OS must keep track of whether the printer has been allocated Use a flag (a bit in memory) as set or clear to indicate that the printer is currently allocated or not But.. testing and setting the flag requires several machine instructions Polly Huang, NTU EE Operating System 62 31

Flag Setting: Step by Step Process OS Printer Device Driver Request for printer Grant access to printer Access printer Check flag clear Set flag Polly Huang, NTU EE Operating System 63 A Possible Problem Process #1 Process #2 OS Printer Device Driver Request for printer Grant access to printer Interrupt process Request for printer Grant access to printer Access printer Resume process Access printer Check flag clear Check flag clear Set flag Polly Huang, NTU EE Operating System 64 32

Quiz Time! Polly Huang, NTU EE Operating System 65 Two Solutions Use the interrupt disable and interrupt enable instructions provided in most machine language When a process request for the printer, the OS disables the interrupt and enables the interrupt when the printing job is completed Use the test-and-set instruction available in many machine language Direct the CPU to retrieve the flag, note the value received, and set the flag, all within a machine instruction Polly Huang, NTU EE Operating System 66 33

Critical Region A.k.a critical section Sequence of instructions that should be executed by only one process at a time Polly Huang, NTU EE Operating System 67 Semaphore A control flag telling if resource is in use Test and set must be done together for non-preemptable resources (e.g., printer) Polly Huang, NTU EE Operating System 68 34

Mutual Exclusion One process already in the critical region Other processes cannot enter the critical region But Polly Huang, NTU EE Operating System 69 Deadlock Two processes block each other from continuing Conditions that lead to deadlock 1. Competition for non-sharable resources 2. At least two resources are needed in common by both processes 3. An allocated resource can not be forcibly retrieved (mutual exclusion) Polly Huang, NTU EE Operating System 70 35

A Deadlock Polly Huang, NTU EE Operating System 71 Examples of Deadlock One process has access to printer but is waiting for tape drive, while another process has access to tape drive but is waiting for printer Scheduler has no space left in the process table and each process in the system must create an additional process before it can complete its task Other examples of deadlock in real life? Polly Huang, NTU EE Operating System 72 36

Removing Deadlocks Deadlock detection and correction schemes Removing Just kill some of the processes Preventing Requiring each process to request all the resources at one time Converting non-shareable resources into shareable ones Spooling Polly Huang, NTU EE Operating System 73 Spooling Postpone requested operation until a later time Each time a process requires the printer, the OS grants the request. However, OS connects the process to a device that stores the information to be printed on a disk When the printer is available, OS transfers the data from the disk to printer Makes a non-shareable resource appear shareable Technique of deadlock avoidance Polly Huang, NTU EE Operating System 74 37

Chapter 3 Operating Systems 3.1 The Evolution of Operating Systems 3.2 Operating System Architecture 3.3 Coordinating the Machine s Activities 3.4 Handling Competition Among Processes 3.5 Security Polly Huang, NTU EE Operating System 75 Two Types of Security Problems Problems from within Attacks from outside Polly Huang, NTU EE Operating System 76 38

To Protect from Problems from Within Operating system prevents illegal access to resources Different memory for different processes Polly Huang, NTU EE Operating System 77 To Protect from Attacks from Outside Access control Privileged instructions only allowed in kernel All file access passes through the kernel Other devices can only be accessed through the kernel Most common protection Require user name and password Polly Huang, NTU EE Operating System 78 39

Hot Attacks Intrusion The pests Polly Huang, NTU EE Operating System 79 Computer Intrusion Undesired access by unauthorized people to your computer system Polly Huang, NTU EE Operating System 80 40

Stealing Passwords Guessing Keep trying until one gets it right Tricking Pretend to be admin and ask you to turn in password Wire-tapping Tapping the computer cable like tapping the phone lines Disguised system daemon asking for passwords Pretend to be the login program Polly Huang, NTU EE Operating System 81 Countermeasure Always tell user when he/she last logged in Report repeated bad guesses Log the guesser into a captive account to spy on the guesser Avoid using public machines Polly Huang, NTU EE Operating System 82 41

Questions? Polly Huang, NTU EE Operating System 83 Quiz Time! Polly Huang, NTU EE Operating System 84 42