Top Banner
Operating Systems Brian Farrimond
66

Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Dec 22, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating Systems

Brian Farrimond

Page 2: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Topics

• Introduction

• Overview of operating system tasks

• Operating systems in detail

Page 3: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Topics

• Introduction

• Overview of operating system tasks

• Operating systems in detail

Page 4: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Computers run software

• Computers– built to run software

• Software– consists of sets of instructions (programs)

Page 5: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Need for system software

• Computers very complex

• Come with large bundles of software to help the non-specialist

• this software is called system software

Page 6: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Types of software

• System software– operating systems– language translators

• Applications software– special purpose programs– e.g. Word, Paintbrush, Internet Explorer

Focus of this course

Page 7: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Topics

• Introduction

• Overview of operating system tasks

• Operating systems in detail

Page 8: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating system tasks

• managing files

• running programs

• memory management

• control of peripherals

• utility programs

Page 9: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating system tasks

• managing files

• running programs

• memory management

• control of peripherals

• utility programs

Page 10: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Managing files

• Programs and data saved on disc as files

• Operating System file manager– organises files– enables user to add, update delete files– controls file ownership in shared system

• e.g. network, mainframe

Page 11: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating system tasks

• managing files

• running programs

• memory management

• control of peripherals

• utility programs

Page 12: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Running programs

• User requests a program– mouse click– program name at command line

• This triggers a sequence of actions– ensure program is in main memory– start fetch execute– manage program’s file access

Page 13: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating system tasks

• managing files

• running programs

• memory management

• control of peripherals

• utility programs

Page 14: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Memory management

• Managing space

• Simultaneous programs – must not interfere with each other’s space

• Large programs– possible to only load required parts– may use use overlays

• e.g. Word with little used menu options

Page 15: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating system tasks

• managing files

• running programs

• memory management

• control of peripherals

• utility programs

Page 16: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Control of peripherals

• Operating system– consists of

• kernel• drivers

• Drivers– plug and

play

Page 17: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating system tasks

• managing files

• running programs

• memory management

• control of peripherals

• utility programs

Page 18: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Utility programs

• Editors

• Compilers

• Clock

• Calculator

• Calendar

Page 19: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Topics

• Introduction

• Overview of operating system tasks

• Operating systems in detail

Page 20: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating systems in detail

• MS-DOS filing system

• Managing disc storage

• Multiprogramming– sharing the processor– sharing memory

Page 21: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating systems in detail

• MS-DOS filing system

• Managing disc storage

• Multiprogramming– sharing the processor– sharing memory

Page 22: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

MS-DOS Filing System

• Micro Soft Disc Operating System– operating system for first PCs– Windows was a layer on top of the MS-DOS– Now Windows replaces MS-DOS

• Shares characteristics of Unix (Linux)– directory structure– command line

Page 23: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

MS-DOS Directories

• Access to files is through a directory– Example: – LETTER.TXT, POEM.TXT, JOKE.TXT

Directory also records: file size, date last changed

Directory is same as a Windows folder

Page 24: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Organise with directory structure

• directory can hold:– file names– sub-directory names

root is top level directory

Page 25: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

File names

• Local name– CHAPTR1

• Full name– \BOOKS\LOSTLOVE\CHAPTR1

Path Local name

Page 26: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Current directory

• User is always “in a directory”

• This is the Current Directory

• Example– opening a file– file dialog’s starting directory

Page 27: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Changing directory

• cd

• Example using full path– cd \LETTERS\LOVELETT

Page 28: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Using short cuts with cd

• cd ..– .. refers to parent directory

Page 29: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating systems in detail

• MS-DOS filing system

• Managing disc storage

• Multiprogramming– sharing the processor– sharing memory

Page 30: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Managing Disc Storage

• Two main types of secondary (permanent) storage– magnetic disc

• floppy disc

• hard disc

– optical disc• CD-ROM

• DVD

Page 31: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Magnetic disc

• flat circular disc (platter)

• coated with magnetizable material

• same technology as– audio cassettes– video tape

Page 32: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Disc pack• Several platters on same spindle

Page 33: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Formatted magnetic disc

• concentric tracks

• each track divided into sectors

Page 34: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Old Disc statistics

Format Surfaces Tracks Sectors / track

Capacity

DD (floppy) 2 80 9 720 Kb

HD (floppy) 2 80 18 1.44 Mb

IBM PS/2 7 583 36 70 Mb

Page 35: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Storing files on disc

• Two alternative strategies for allocating sectors to a file– contiguous allocation

• file stored on adjacent sectors

– non-contiguous allocation• file scattered across disc

Page 36: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Contiguous allocation• Advantages

– simple to implement– fast

• Problems– need to find large

enough slot on disc– difficult to add to file– fragmentation on

deletion

Page 37: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Non-contiguous allocation

• The most common approach

• Method:– files chopped up into fixed size blocks– blocks need not be stored in adjacent sectors

Page 38: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Non-contiguous allocation

• Disadvantages– more complex to implement– increased access time– most files waste space in incompletely filled

blocks

• Advantage– increased flexibility

Page 39: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Block size

• How big should blocks be ?– too big then too much space wasted– too small then considerable effort needed to

retrieve file

• MS-DOS– block = 2 x 512 byte sectors– known also as a cluster

Page 40: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Storing a file

• operating system ...– obtains a free block– starts filling it with data– when full, obtains another block– continue until all file is stored

• Problems to solve:– recording sequence of blocks making up a file– keeping track of free blocks

Page 41: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

The MS-DOS Solution

File Allocation Table (FAT)Directory Entry

A directory

Page 42: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating systems in detail

• MS-DOS filing system

• Managing disc storage

• Multiprogramming– sharing the processor– sharing memory

Page 43: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Multiprogramming

• First machines– single user

• More modern machines– multiple users

• e.g. bank system

– each user perhaps running several programs at same time

• e.g. Windows PC

Page 44: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Achieving multiprogramming

• Single CPU– Concurrent execution– CPU continually switches between programs– C.f. chess grandmaster playing lots of club

players “simultaneously”

• Multiple CPUs– Parallel execution– Each program runs on a separate CPU

Page 45: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Virtual machines

• Each user sharing a machine appears to have machine to themselves

• One real machine

-> many virtual machines

• Two main issues:– Sharing the processor– Sharing main memory

Page 46: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Sharing the processor

• Original problem:– expensive , fast CPU waiting for slow

peripherals – uneconomic

• Solution– have CPU run another program while waiting

Page 47: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Other advantages

• Carry out tasks simultaneously– E.g. control central heating and word process

• Share peripherals– Mainframe and minis can centralise printers etc– Dumb terminals are cheap

• Share data– Users can access same files

• Concurrent programs on same machine– This is how we use Windows

Page 48: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Disadvantages

• Breakdowns affect everybody

• Portability – need link to central machine

• Expense – but getting cheaper

• Security risks

Page 49: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Switching between programs

• Done by the kernel (part of operating system)

• Known as a context switch

• Each program needs a control block– Preserves program’s state

• CPU register contents

• Which data files are opened

Page 50: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Strategies for switching

• When program finished or blocked– Simple to implement– But, programs can hog the processor

• At regular intervals (time slicing)– Programs cannot hog processor– But, complex to control so time overhead– This is the strategy in common use

Page 51: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Time slicing

Each interval is a time sliceBlocked programs (waiting

for a peripheral) are not allocated time slices

Scheduling – deciding which program runs next

Page 52: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Running programs are “processes”

• Processes consist of:– The program (set of instructions)– Current state of data structures– Current state of CPU registers– Which I/O devices currently open– Which files are currently open

Page 53: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Process states

• Running– During its timeslice

• Ready– While some other process is running

• Blocked– Unable to proceed e.g. waiting for input device

Page 54: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Context switching with interrupts

• Interrupt– Signal to CPU to

stop what it is doing and execute an interrupt routine

– Clock interrupt generated by clock at fixed intervals

Page 55: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Operating systems in detail

• MS-DOS filing system

• Managing disc storage

• Multiprogramming– sharing the processor– sharing memory

Page 56: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Sharing the Memory

• Programs need to be in main memory when executing

• May not all fit in

Page 57: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Sharing by swapping

• Program and data– copied into memory at beginning of each time slice

– copied back to disc at end of time slice

• All main memory available to program• But, high overhead of swapping time

Page 58: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Sharing by paging

• Divide program and data into pages

• Only swap in the pages needed during time slice

• Memory divided into pageframes– One page per pageframe

Page 59: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Loading pages

• Pages can be loaded in any order• Use a page table to keep track

Page 60: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Translating addresses

• Given an instruction like JMP 314

• 314 means 314 locations from beginning of program

• Assume each page 100 locations long

• JMP 314 means– page 3 offset 14

• Where is the location in real memory ?

Page 61: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Carrying out the translation

JMP 314

Page number

Real memory address: 2514

Page 62: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Page fault

• Interrupt generated when required page not in main memory

• Causes– Required page to be fetched from disc– Page table updated– Program continues

Page 63: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Thrashing

• Page faults are too frequent

• Most time spent swapping pages

• Caused by:– Bad program design– Too many programs attempting to run

concurrently

Page 64: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Paging strategies

• Fetch strategy– When to fetch a page

• Replacement strategy– When to swap page out

Page 65: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Fetch strategies

• Demand fetch

• Anticipatory fetch

Page 66: Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating systems in detail.

Replacement strategies

• Optimal page replacement

• Longest resident

• Least recently used

• Least frequently used