Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating...
-
date post
22-Dec-2015 -
Category
Documents
-
view
217 -
download
2
Transcript of Operating Systems Brian Farrimond. Topics Introduction Overview of operating system tasks Operating...
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
Computers run software
• Computers– built to run software
• Software– consists of sets of instructions (programs)
Need for system software
• Computers very complex
• Come with large bundles of software to help the non-specialist
• this software is called system software
Types of software
• System software– operating systems– language translators
• Applications software– special purpose programs– e.g. Word, Paintbrush, Internet Explorer
Focus of this course
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
Operating system tasks
• managing files
• running programs
• memory management
• control of peripherals
• utility programs
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
Operating system tasks
• managing files
• running programs
• memory management
• control of peripherals
• utility programs
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
Operating system tasks
• managing files
• running programs
• memory management
• control of peripherals
• utility programs
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
Operating system tasks
• managing files
• running programs
• memory management
• control of peripherals
• utility programs
Control of peripherals
• Operating system– consists of
• kernel• drivers
• Drivers– plug and
play
Operating system tasks
• managing files
• running programs
• memory management
• control of peripherals
• utility programs
Utility programs
• Editors
• Compilers
• Clock
• Calculator
• Calendar
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
Operating systems in detail
• MS-DOS filing system
• Managing disc storage
• Multiprogramming– sharing the processor– sharing memory
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
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
Organise with directory structure
• directory can hold:– file names– sub-directory names
root is top level directory
File names
• Local name– CHAPTR1
• Full name– \BOOKS\LOSTLOVE\CHAPTR1
Path Local name
Current directory
• User is always “in a directory”
• This is the Current Directory
• Example– opening a file– file dialog’s starting directory
Changing directory
• cd
• Example using full path– cd \LETTERS\LOVELETT
Using short cuts with cd
• cd ..– .. refers to parent directory
Operating systems in detail
• MS-DOS filing system
• Managing disc storage
• Multiprogramming– sharing the processor– sharing memory
Managing Disc Storage
• Two main types of secondary (permanent) storage– magnetic disc
• floppy disc
• hard disc
– optical disc• CD-ROM
• DVD
Magnetic disc
• flat circular disc (platter)
• coated with magnetizable material
• same technology as– audio cassettes– video tape
Disc pack• Several platters on same spindle
Formatted magnetic disc
• concentric tracks
• each track divided into sectors
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
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
Contiguous allocation• Advantages
– simple to implement– fast
• Problems– need to find large
enough slot on disc– difficult to add to file– fragmentation on
deletion
Non-contiguous allocation
• The most common approach
• Method:– files chopped up into fixed size blocks– blocks need not be stored in adjacent sectors
Non-contiguous allocation
• Disadvantages– more complex to implement– increased access time– most files waste space in incompletely filled
blocks
• Advantage– increased flexibility
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
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
The MS-DOS Solution
File Allocation Table (FAT)Directory Entry
A directory
Operating systems in detail
• MS-DOS filing system
• Managing disc storage
• Multiprogramming– sharing the processor– sharing memory
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
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
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
Sharing the processor
• Original problem:– expensive , fast CPU waiting for slow
peripherals – uneconomic
• Solution– have CPU run another program while waiting
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
Disadvantages
• Breakdowns affect everybody
• Portability – need link to central machine
• Expense – but getting cheaper
• Security risks
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
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
Time slicing
Each interval is a time sliceBlocked programs (waiting
for a peripheral) are not allocated time slices
Scheduling – deciding which program runs next
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
Process states
• Running– During its timeslice
• Ready– While some other process is running
• Blocked– Unable to proceed e.g. waiting for input device
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
Operating systems in detail
• MS-DOS filing system
• Managing disc storage
• Multiprogramming– sharing the processor– sharing memory
Sharing the Memory
• Programs need to be in main memory when executing
• May not all fit in
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
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
Loading pages
• Pages can be loaded in any order• Use a page table to keep track
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 ?
Carrying out the translation
JMP 314
Page number
Real memory address: 2514
Page fault
• Interrupt generated when required page not in main memory
• Causes– Required page to be fetched from disc– Page table updated– Program continues
Thrashing
• Page faults are too frequent
• Most time spent swapping pages
• Caused by:– Bad program design– Too many programs attempting to run
concurrently
Paging strategies
• Fetch strategy– When to fetch a page
• Replacement strategy– When to swap page out
Fetch strategies
• Demand fetch
• Anticipatory fetch
Replacement strategies
• Optimal page replacement
• Longest resident
• Least recently used
• Least frequently used