real operating systems - warwick.ac.ukwhite real operating systems introduction dos windows unix...
TRANSCRIPT
Real Operating SystemsLecture #12
Department of Computer Science and TechnologyUniversity of Bedfordshire
Written by David Goodwin,based on the lecture series of Dayou Li
and the book Understanding Operating Systems 4thed.by I.M.Flynn and A.McIver McHoes (2006).
Operating Systems, 2012
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
Outline
IntroductionDOSWindowsUnix & Linux
Memory ManagementDOSWindowsLinux
Process ManagementDOSWindowsLinux
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
INTRODUCTION TO DIFFERENTO/Ss
I Three typical operating systemsI Disk operating system (DOS)I WindowsI Unix/Linux
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
DOS
I HistoryI In 1980, IBM looked for an operating system for its
soon-to-be-released 6-bit personal computersI Digital Research offered CP/M-86I Softech offered P-SystemI MS
I MS also looked for OS for its 16-bit computersI Seattle Computer Products offered 86-DOSI MS bought it and renamed it MS-DOS
I IBM chose MS-DOS in 1981 and called it PC-DOSI MS-DOS evolved from v 1.0 to v 6.22 from 1981 to
1994
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
DOS
I FeaturesI Single user, stand-alone
desktopI Command-lineI Commands are based on
wordsI Examples
I COPY – copy a fileI DEL – delete a fileI PRINT – print files on a
printerI DIR – list files in this
directoryI MD – make a new
directoryI CHKDSK – check the diskI COMP – compare two
files
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
Layers of DOS
I Three layers:I Top layer – command processor
I Sends prompts to userI Accepts commandsI Executes commands (including interpret commands to
machine language)I Issues responses
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
Layers of DOS
I I Middle layer – DOS kernelI A program containing routines that are needed for
interfacing diskI Stored in MSDOS.SYS fileI Read to memory during initialisation time
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
Layers of DOS
I I Bottom layer – BIOS (Basic Input/Output System)I Interfaces I/O devices such as printer, monitor and
keyboardI Controls data flow to and from these devicesI Receive statues information about these devices
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS
I HistoryI Initiative
I To allow users to not have to remember and usesystem commands but via a user-friendly interface –GUI
I Not a replacement of DOS
I Early versions (1985 to 1992)I Windows 1.0 to 3.1 are only “interfaces” between GUI
and DOSI Single-user rather than networked
I True O/S since 1992I Windows 95 is first true O/S
I Network O/SI Windows NT version 3.1 in 1993 led by David Cutler
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS - Design goals
I Extensibility – be easily enhanced to meet changes overtime to support new hardware and software technologies
I Privileged process and non-privileged processesI Kernel mode refers to the privileged mode of a
processorI All instructions are allowedI System memory is accessible
I Use mode refers to the non-privileged mode of aprocessor
I Only certain instructions are allowedI System memory is not accessible
I O/S executes in kernel modeI Application programs (protected subsystems) run in
user mode
I Modular structure
I Drivers for new file systems, devices and networks
I Objects – abstract data types
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS - Design goals
I Portability – ability for O/S to operate on differentmachines that use different processors or configurations
I Code is modularI Standard high-level programming language c/c++ is
used for implementationI Hardware abstraction layer (HAL) providing isolation
from hardware dependenciesI HAL abstracts hardware such as caches with a layer of
low-level software so that higher-level code needs nochange when moving from one platform to another
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS - Design goals
I Reliability – predictability in responding to errorconditions, including hardware failures
I Modular designI NTFS to recover all types of errorsI US government-certifiable securityI Virtual memory strategy to prevent one user from
reading or modifying memory that is occupied byanother user
I Compatibility – ability of an O/S to execute programswritten for other O/Ss
I Execution environments for applications that differ fromWin32 API
I Source-level compatibility to POSIX (PortableOperating System Interface for Computer Environment)
I Supporting already-existing file systems
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS - Design goals
I Performance – fast response timesI Crucial processes such as system calls and page faults
are tested and optimisedI LPC (local procedure call) to guarantee fast
communications among the protected subsystemsI Carefully designing the environment subsystems to
ensure the speed of frequently used systems servicesI Critical elements of Windows’ networking software are
built in the privileged protion
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
UNIX AND LINUX
I Advantages shared by Unix and LinuxI PortableI Powerful utilitiesI Device independent
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
UNIX AND LINUX
I Evolution of UNIX
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
UNIX AND LINUX
I Evolution of LINUX
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
UNIX AND LINUX - Design goals
I Supporting software development
I Keeping its algorithms as simple as possible
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
DOS MEMORY MANAGEMENT
I ROM and RAMI ROM contains a section of BIOS for
starting up a computerI RAM is mail memory where programs
are loadedI Interrupt vectorsI BIOS interfaceI DOS kernelI Buffer cacheI Installable drivesI Resident part of COMMAND.COMI TSRI User memoryI Transient part of COMMAND.COMI Reserved for BIOS
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
DOS MEMORY MANAGEMENT
I TPA allocation “policy”I Reason for allocating memory blocks in TPA for more
than one programsI Improving efficiency when executing or accessing the
next program/file after executing one program
I “Policy”I Dynamic allocationI Modification – modifying (normally giving more)
memory blocks to a running program when it requiresmore for, e.g., I/O purposes
I Release of main memory– after part of a program isexecuted
I For .EXE files – allocating the max memory needed ifTPA has enough free memory, otherwise, giving themin memory
I For .COM files – allocating all memory it may needdespite it will use or not
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
DOS MEMORY MANAGEMENT
I TPA allocation algorithmsI First-fit was used in early version and Best-fit was used
in later versionI A block can be as small as 16 bytes (also known as
paragraph) and as large as the max available memory(TPA)
I The first five bytes have special usage:I Byte 0 – indicator of the last block (90h if yes, 77h
otherwise)I Byte 1– indicator of status of the block (00h for busy)I Byte 2 – pointer to PSPI Bytes 3 and 4 – indicator of the number of paragraph
contained in the block
I List of busy/free blocksI List is a data structure containing a head and a tailI An algorithm searches for a free block in the list for a
file
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS MEMORY MANAGEMENT
I Memory manage challenge and solutionI Challenge is to run programs written for Windows, DOS
and POSIX without clashing each other in memoryI Solution is to separate system memory and application
memoryI Example
I 4GB memory with 2GB each allocated for applicationstorage and system storage
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS MEMORY MANAGEMENT
I Virtual memory managerI To allow applications to share memoryI Allocate memory in two stages:
I Reserving memoryI Committing memory
I Read/write protection for virtual memory so read/writeperformed by one process won’t be interrupted by otherprocesses
I Lock virtual memory pages in physical memory toensure that a critical page won’t be removed frommemory while a process is using it
I Retrieve informationI Protect virtual pagesI Rewrite virtual pages to disk
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS MEMORY MANAGEMENT
I ImplementationI Address space management
I System storage section of the virtual memory can onlybe accessed by kernel-mode processes
I Addresses of the lower part of this section aretranslated by hardware to have a fast access speed
I PagingI Fetch policy determines time when copying a page
from memory to diskI Placement policy is a set of rules determining where
the vurtual pages are loaded in memoryI Replacement policy determines which virtual page
must be removed from memory to make room for newpages
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
LINUX MEMORY MANAGEMENT
I Swapping and demand pagingI Swapping a job out of memory
I Round robin policy is used – jobs/processes aremanaged by round robin and if a job’s time slice is upor when it generate an I/O interrupt, the entire job willbe swapped out to secondary storage to make room foranother job that is waiting in the READY queue
I Demand pagingI ImageI Program codeI DataI stack
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
LINUX MEMORY MANAGEMENT
I UNIX kernelI Responding system calls issued by processesI Set up memory boundaryI Permanently resides in memoryI Uses the least recently used (LRU) page replacement
algorithm
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
DOS PROCESS MANAGEMENT
I Designed for single-task and single user environmentI Parent child processes – parent process calls child
process and then goes to sleep and remains asleep whilethe child process is running
I One process runs at a timeI The child process can interrupt the parent processI 256 interrupts
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
DOS PROCESS MANAGEMENT
I Reason for interruptsI No need for having any sophisticated process
management as MS-DOS is designed for single user in asingle task environment
I A task/process sometimes does need to be interrupted ,for example, when it waits for a peripheral device, toimprove efficiency
I Process life cycle: ready – running – waiting – exitI Synchronisation among tasks/processes is needI Synchronisation is achieved in MS-DOS via interrupts
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
DOS PROCESS MANAGEMENT
I Different types of interruptsI Internal hardware interrupts
I Generated by certain event during a program’sexecution, for example, divided by zero
I Every such event is assigned with a specific interruptnumber which is electronically wired into the processorand therefore cannot be modified
I External hardware interruptsI Caused by peripheral device controllersI Also assigned with specified numbers and cannot be
modified
I Software interruptsI Generated by system and application programsI Some are used to activate specialised application
programs
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
DOS PROCESS MANAGEMENT
I Interrupt synchronisationI Stack for
I PSW (Program Statuts Word)I code segment registerI instruction pointer register
I Disables the interrupt system until the current interrupthas been solved
I Placing a 8-bit number on the systems bus
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS PROCESS MANAGEMENT
I MultithreadingI Elements of a process
I An executable programI Private memory areaI System resources allocated by an O/SI At least one thread of execution
I Elements of a threadI A unique identifierI The contents of a volatile set of register indicating the
processor’s stateI Two stacks used during the thread exectuionI A private storage area used by subsystems and
dynamic-link libraries
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
WINDOWS PROCESS MANAGEMENT
I Multithreading synchronisationI Problem
I Several treads can modify the same global variableindependently of each other
I Competition/racing for single shared resource
I Synchronisation in Win32I Mutexes – only one thread can own the resource at a
timeI Semaphores – multiple threads can own it at a timeI Critical section – a critical section can only be owned
by a process and cannot be shared between processesI Event object – it is sent to all threads to alert them of
an action occurring
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
LINUX PROCESS MANAGEMENT
I PriorityI Priority is largely determined by accumulated CPU timeI Computer-to-total-time ratio:
CPU time a process has used
Total time CPU time required by the process
I A process that has used a lot CPU time gets the lowestpriority
I Computer-to-total-time ratio is updated every secondI Round-robin is used to decide which process will run
first among those that have the same priority
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
LINUX PROCESS MANAGEMENT
I TablesI Process with sharable
codeI Resident Section
of memory has twotables
I Process Tableshows all processes
I Text Table showsthe relationshipbetween theprocesses andcode, i.e. whichprocesses share thesame code and thememory address ofthe code
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
LINUX PROCESS MANAGEMENT
I I I Transient Section has Data area, Code area and UserTable for each process
I Data and code are stored separately because code issharable
I User Table is a map between Data area and Code areaso it controls the access privilege of data/files
I Example – P3 and P4I Processes with nonsharable code
I Data and code are stored in the same areaI Example – P5
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
LINUX PROCESS MANAGEMENT
I Fork, wait and execI fork
I Creates a copy of a processI The original one is called parentI The copy is called child
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
LINUX PROCESS MANAGEMENT
I I waitI Allows programmers to synchronise process execution
bg=whiteReal Operating
Systems
Introduction
DOS
Windows
Unix & Linux
MemoryManagement
DOS
Windows
Linux
ProcessManagement
DOS
Windows
Linux
LINUX PROCESS MANAGEMENT
I I execI Is a family of commands – execl, execv, execls, execlp
and execvpI Are used to start a process from another process