Chapter 1
Chapter 1
Introduction to
operating systems
1
What is an operating system?
• A program that
– controls the execution of a program and
– acts as an intermediary between a user of a computer and the
computer hardware
Application programs
Utilities
Operating System
Hardware
2
History of Operating Systems
• First generation 1945 - 1955
– vacuum tubes, plug boards
– Operating systems were unheard of
• Second generation 1955 - 1965
– transistors, assembly and FORTRAN
– Batch system was introduced
• Third generation 1965 – 1980
– ICs and multiprogramming
• Fourth generation 1980 – present
– personal computers
3
Second Generation
– Focused on cost effectiveness
– Computers were expensive
• IBM 7094: $200,000
– Two widely adopted improvements
• Computer operators: humans hired to facilitate
machine operation
• Concept of job scheduling: group together
programs with similar requirements
– Expensive time lags between CPU and I/O
devices
4
Second Generation
9
Fourth Generation
– Cost/performance ratio improvement of
computer components
– More flexible hardware (firmware)
– Multiprocessing
• Allowed parallel program execution
– Evolution of personal computers
– Evolution of high-speed communications
– Distributed processing and networked
systems introduced
10
Fourth Generation
– Demand for Internet capability
• Sparked proliferation of networking capability
• Increased networking
• Increased tighter security demands to protect
hardware and software
– Multimedia applications
• Demanding additional power, flexibility, and
device compatibility for most operating systems
11
History of Operating Systems
Recent Developments
Second Generation
Distributed computing,
Job scheduling, JCL, faster personal computers, high-
I/O, spooling, batch, files speed communication,
multi-media
13
Basic Elements
• Processor
• Main Memory
– volatile
– referred to as real memory or primary memory
• I/O modules
– secondary memory devices
– communications equipment
– terminals
• System bus
– communication among processors, memory, and
I/O modules
14
Top-Level Components
CPU Main Memory
• 0
System • 1
• 2
PC MAR Bus
Instruction
Instruction
Instruction
IR MBR •
•
I/O AR •
Data
Execution
Data
unit I/O BR
Data
Data
•
•
I/O Module • n- 2
n- 1
PC = Program counter
Buffers IR = Instruction register
MAR = Memory address register
MBR = Memory buffer register
I/O AR= Input/output address register
I/O BR= Input/output buffer register
17
Control and Status Registers
• Program Counter (PC)
– Contains the address of an instruction to be fetched
• Instruction Register (IR)
– Contains the instruction most recently fetched
• Program Status Word (PSW)
– Condition codes
– Interrupt enable/disable
– Supervisor/user mode
• Condition Codes or Flags
– Bits set by the processor hardware as a result of
operations
– Examples
• Positive result
• Negative result
• Zero
• 18
Overflow
Processor
• Internal registers
– Memory address register (MAR)
• Specifies the address for the next read
or write
– Memory buffer register (MBR)
• Contains data written into memory or
receives data read from memory
– I/O address register
– I/O buffer register
19
Instruction Execution
• Two steps
– Processor reads instructions from memory
• Fetches
– Processor executes each instruction
20
Instruction Fetch and Execute
• The processor fetches the instruction
from memory
• The fetched instruction is loaded to IR
• Program counter (PC) holds address of
the instruction to be fetched next
• Program counter is incremented after
each fetch to point to the next
instruction
21
Instruction Register
• Categories of instruction
– Processor-memory
• Transfer data between processor and memory
– Processor-I/O
• Data transferred to or from a peripheral device
– Data processing
• Arithmetic or logic operation on data
– Control
• Alter sequence of execution
22
Interrupts
• Interrupt the normal sequencing of the processor
• Most I/O devices are slower than the processor
– Processor must pause to wait for device
24
Interrupt Handling
• When CPU is interrupted, it stops what it is doing
and immediately transfers execution to a fixed
location.
• The operating system preserves the state of the
CPU by storing registers and the program counter.
• Determines which type of interrupt has occurred:
– polling
– vectored interrupt system
• Separate segments of code determine what action
should be taken for each type of interrupt
25
Interrupts
• Suspends the normal sequence of execution
26
Interrupt Cycle
Processor checks
for interrupts
If no interrupts fetch
the next instruction for the current program
If an interrupt is pending, suspend execution of the
current program, and execute the interrupt-handler
routine 27
Interrupt Timeline
28
I/O Structure
Synchronous
• After I/O starts, control returns to user
program only upon I/O completion.
– Wait instruction idles the CPU until the next
interrupt
– Wait loop (contention for memory access).
– At most one I/O request is outstanding at a
time, no simultaneous I/O processing.
29
I/O Structure
Asynchronous
• After I/O starts, control returns to user
program without waiting for I/O completion.
– System call – request to the operating system to
allow user to wait for I/O completion.
– Device-status table contains entry for each I/O
device indicating its type, address, and state.
– Operating system indexes into I/O device table
to determine device status and to modify table
entry to include interrupt.
30
Two I/O Methods
Synchronous Asynchronous
31
Storage Structure
• Main memory – the only large storage media that
the CPU can access directly.
• Secondary storage – extension of main memory
that provides large nonvolatile storage capacity.
• Magnetic disks – rigid metal or glass platters
covered with magnetic recording material
– Disk surface is logically divided into tracks, which
are subdivided into sectors.
– The disk controller determines the logical interaction
between the device and the computer.
32
Storage Hierarchy
• Storage systems organized in hierarchy.
– Speed
– Cost
– Volatility
• Caching – copying information into faster
storage system; main memory can be
viewed as a last cache for secondary
storage.
33
Storage-Device Hierarchy
34
Caching
• Important principle, performed at many levels in a
computer (in hardware, operating system, software)
• Information in use copied from slower to faster
storage temporarily
• Faster storage (cache) checked first to determine if
information is there
– If it is, information used directly from the cache (fast)
– If not, data copied to cache and used there
• Cache smaller than storage being cached
– Cache management important design problem
– Cache size and replacement policy
35
Migration of Integer A from Disk to Register
• Multitasking environments must be careful to use most
recent value, not matter where it is stored in the storage
hierarchy
36
Operating system overview
37
Operating System Objectives
• Convenience
– Makes the computer more convenient to use
• Efficiency
– Allows computer system resources to be used
in an efficient manner
• Ability to evolve
– Permit effective development, testing, and
introduction of new system functions without
interfering with service
38
Operating System Objectives
• Convenience
– Makes the computer more convenient to use
• Efficiency
– Allows computer system resources to be used in
an efficient manner
• Ability to evolve
– Permit effective development, testing, and
introduction of new system functions without
interfering with service
39
Services Provided by the OS
• Program development
– Utility programs like editors and debuggers
• Program execution
– Handles the scheduling duties like loading
instructions and data into main memory, initializing
I/O devices and files, and preparing other resources
must be prepared
• Access to I/O devices
– OS provides a uniform interface that hides details of
I/O operations to the devices so that programmers
can access them using simple reads and writes.
40
Services Provided by the OS
• Controlled access to files
– Reflects detailed understanding structure of the
data contained in the files on the storage medium
– In case of multiple users, the OS may provide
protection mechanisms to control access to the
files
• System access
– Provides protection of resources and data from
unauthorized users and must resolve conflicts for
resource contention
41
Services Provided by the OS
• Error detection and response
– Errors that may occur
• Internal and external hardware errors
– Memory error
– Device failure
• Software errors
– Arithmetic overflow
– Access forbidden memory locations
• Operating system cannot grant request of application
– OS must provide a response that clears the error condition with the least
impact on running applications
– The response may include:
• ending the program that caused the error
• retrying the operation or
• simply reporting the error to the application.
42
Services Provided by the OS
• Accounting
– Collect usage statistics
– Monitor performance
– Used to anticipate future enhancements
– Used for billing purposes
43
Operating System Objectives
• Convenience
– Makes the computer more convenient to use
• Efficiency
– Allows computer system resources to be used in an
efficient manner
• Ability to evolve
– Permit effective development, testing, and
introduction of new system functions without
interfering with service
44
Operating system subsystems
• OS includes four essential subsystem managers
– Memory Manager
– Processor Manager
– Device Manager
– File Manager
• Network Manager (fifth subsystem manager)
– In all modern operating systems
– Assumes responsibility for networking tasks
45
Operating system subsystems
46
Operating system subsystems
• Each manager:
– Works closely with other managers
– Performs a unique role
• Manager tasks
– Monitor its resources continuously
– Enforce policies determining:
• Who gets what, when, and how much
– Allocate the resource (when appropriate)
– Deallocate the resource (when appropriate)
47
Operating system subsystems
• Network Manager
– Operating systems with networking capability
– Fifth essential manager
– Convenient way for users to share resources
– Retains user access control
• Resources include:
– Hardware (CPUs, memory areas, printers, tape
drives, modems, and disk drives)
– Software (compilers, application programs, and data
files)
48
Operating system subsystems
• Memory Manager
– In charge of main memory
• Random Access Memory (RAM)
– Responsibilities include:
• Preserving space in main memory occupied by
operating system
• Checking validity and legality of memory space request
• Setting up memory tracking table
– Tracks usage of memory by sections
– Needed in multiuser environment
• Deallocating memory to reclaim it
49
Operating system subsystems
• Processor manager
– In charge of allocating Central Processing
Unit (CPU)
– Tracks process status
• An instance of program execution
– Two levels of responsibility:
• Handle jobs as they enter the system
– Handled by Job Scheduler
• Manage each process within those jobs
– Handled by Process Scheduler
50
Operating system subsystems
• Device manager
– In charge of monitoring all resources
• Devices, channels, and control units
– Responsibilities include:
• Choosing most efficient resource allocation method
– Printers, ports, disk drives, etc.
– Based on scheduling policy
• Allocating the device
• Starting device operation
• Deallocating the device
51
Operating system subsystems
• File manager
– In charge of tracking every file in the system
• Data files, program files, compilers, application programs
– Responsibilities include:
• Enforcing user/program resource access restrictions
– Uses predetermined access policies
• Controlling user/program modification restrictions
– Read-only, read-write, create, delete
• Allocating resource
– Opening the file
– Deallocating file (by closing it)
52
Operating system subsystems
• Cooperation issue
– Essential manager
• Perform individual tasks and
• Harmoniously interact with other managers
– Requires incredible precision
• No single manager performs tasks in isolation
• Network manager
– Convenient way to share resources
– Controls user access
53
Operating System Objectives
• Convenience
– Makes the computer more convenient to use
• Efficiency
– Allows computer system resources to be used in
an efficient manner
• Ability to evolve
– Permit effective development, testing, and
introduction of new system functions without
interfering with service
54
Ease of Evolution of OS
• Hardware upgrade plus new types of HW
• New services
– In response to demands of users or system
managers
– Examples:
• Maintain good performance
• Applications require windows
• Fixes
– Any operating system has faults
– A fix to a fault my introduce another fault
55
Process
• The concept of process is fundamental to the
structure of operating systems
• Definitions:
– A program in execution
– An instance of a program running on a
computer
– The entity that can be assigned to and
executed on a processor
– A unit of activity characterized by a single
sequential thread of execution, a current
state, and an associated set of system
resources 56
Process
• Associated with each process is its
address space
– a list of memory locations from some minimum
(usually 0) to some maximum
• which the process can read and write
• The address space contains
– the executable program
– the program’s data
– Execution context of the program
• Information needed by the OS to manage the process
57
Threads
• Multiple actions executing simultaneously
– Heavyweight process (conventional process)
• Owns the resources
• Passive element
– Lightweight process (thread)
• Uses CPU and scheduled for execution
• Active element
– Multithreaded applications programs
• Contain several threads running at one time
• Same or different priorities
• Examples: Web browsers and time-sharing systems
58
Uniprogramming
• I/O devices are slow compared to the processor
• Processor can’t switch to another process
• It must wait for I/O instruction to complete before
preceding
59
59
Multiprogramming
• When one job needs to wait for I/O, the
processor can switch to the other job
60
60
Multiprogramming
• Multiprogramming needed for efficiency
– Single user cannot keep CPU and I/O devices
busy at all times
– Multiprogramming organizes jobs (code and
data) so CPU always has one to execute
– A subset of total jobs in system is kept in
memory
– One job selected and run via job scheduling
– When it has to wait (for I/O for example), OS
switches to another job
61
Timesharing
• Just as multiprogramming allows the processor
to handle multiple batch jobs at a time,
multiprogramming can also be used to handle
multiple interactive jobs.
– In this latter case, the technique is referred to as time
sharing, because processor time is shared among
multiple users
• Operating system decides to stop running one
process and start running another (timesharing)
– One process has had more than its share of CPU time
• All information about the process must be
explicitly saved somewhere during the
suspension
62
Timesharing
• Process will later be restarted in exactly the same
state it had when it was stopped
• In a time-sharing system, multiple users
simultaneously access the system through terminals,
with the OS interleaving the execution of each user
program in a short burst or quantum of computation.
• Thus, if there are n users actively requesting service
at one time, each user will only see on the average
1/n of the effective computer capacity, not counting
OS overhead
• Given the relatively slow human reaction time, the
response time on a properly designed system should
be similar to that on a dedicated computer
63
Types of Operating Systems
• Five categories
– Batch
– Interactive
– Real-time
– Hybrid
– Embedded
• Two distinguishing features
– Response time
– How data enters into the system
64
Types of Operating Systems
• Batch Systems
– Input relied on punched cards or tape
– Efficiency measured in throughput
• Interactive Systems
– Faster turnaround than batch systems
– Slower than real-time systems
– Introduced to provide fast turnaround when
debugging programs
– Time-sharing software developed for operating
system
65
Types of Operating Systems
• Real-time systems
– Reliability is key
– Fast and time limit sensitive
– Used in time-critical environments
• Space flights, airport traffic control, high-speed aircraft
• Industrial processes
• Sophisticated medical equipment
• Distribution of electricity
• Telephone switching
– Must be 100% responsive, 100% of the time
66
Types of Operating Systems
• Hybrid systems
– Combination of batch and interactive
– Accept and run batch programs in the background
• Interactive load is light
• Embedded systems
– Computers placed inside other products
– Adds features and capabilities
– Operating system requirements
• Perform specific set of programs
• Not interchangeable among systems
• Small kernel and flexible function capabilities
67