Chapter One
___________________________
Introduction to Operating Systems
1
Outline
Definition
Objectives of OS
History of OS
Computer HW review
Interrupts
OS services
System calls
OS structures
2
What is Operating System?
No universally accepted definition
A program that acts as an intermediary between user applications
and the computer hardware
User
Applications
Virtual Machine Interface
Operating
System
Physical Machine Interface
Hardware
A special pieces of software that abstracts and arbitrates the use
of computer systems
Abstract (simplify, multiplex h/w)
Arbitrate (referees the use of computing resources )
Operating system is the one program running at all times on the
computer—usually called the kernel.
3
What is operating system?
Important feaures of OS
abstracts the computer hardware
Hides the messy details of the underlying
hardware
Presents users with a resource abstraction that
is easy to use
Extends or virtualizes the underlying machine
Manages computing resources
Resources
Processors, memory, timers, disks, mice,
network interfaces, printers, displays, …
Responsible for allocating resources for users
and processes
Should ensure that no starvation, allocation is
based on desired policy( like FCFS) and efficient
system utilization.
Provides isolation and protection
Isolates user programs from the OS
Isolates one user program from another
Protects illegal access/actions
4
What Operating Systems Do ?
The role of OS can be viewed from two perspectives:
user view and system view
User view -As seen by the end user
Varies according to the interface being used.
Users sit at PC (have dedicated resources):
OS goal is Providing ease of use and good performance
User at the terminal connected to mainframe or
minicomputer
must keep all users happy
OS goal is resource utilization (Sharing resources)
Users sit at PC connected to other workstation and
servers
OS goal is to compromise between usability and resource
utilization
5
Cont’d
System view – from the computer point of view, OS
is related with HW
OS is a resource allocator
Manages all resources such as I/O devices, memory, CPU etc
Decides between conflicting requests for efficient and fair
resource use
OS is a control program
Controls execution of programs to prevent errors and improper
use of the computer(Especially the I/O devices)
6
Operating System Objectives
Convenience
Make the computer more convenient to use
Abstraction
Hardware-independent programming model
Efficiency
Allows the computer system to be used in an efficient manner
Ability to evolve
Permit effective development, testing, and introduction of
new system functions without interfering with existing
services
Protection
allow only authorised access to data, computation, services,
etc.
7
History of Operating Systems
First generation: 1945–1955
Vacuum tubes and plugboards (no OS)
Second generation: 1955–1965
Transistors, batch systems
Third generation: 1965–1980
Integrated circuits and multiprogramming
Fourth generation: 1980–present
Personal computers, mobile devices, sensors
8
History of Operating Systems
(1955–1965)
Early batch system
Single user
Secure
Programmer/user as the operator
But low CPU utilization: slow mechanical I/O devices
9
History of Operating Systems
(1965–1980)
Multiprogramming system
Three jobs in memory: 3rd generation
Spooling: use disk as very large buffer for input/output devices
Timesharing: quick response time
10
History of Operating Systems
(1980–present)
Mainframe operating systems
Server operating systems
Personal computer operating systems
Real-time operating systems
Embedded operating systems
Smart card operating systems
11
Reading assignment 1
Read about history of OS and types of OS
References
MOS book
12
Computer System Organization
Computer organization specifies the different parts of the system
and how they do fit together
13
Computer-System Operation
I/O devices and the CPU can execute concurrently
Each device controller is in charge of a particular device
type
Each device controller has a local buffer
CPU moves data from/to main memory to/from local
buffers
Device controller informs CPU that it has finished its
operation by causing an interrupt
14
Common Functions of Interrupts
Interrupt is a mechanism that force the CPU to stop
what it’s doing currently and moves the control to
other routine
Interrupt transfers control to the interrupt service
routine
Generally, through the interrupt vector, which
contains the addresses of all the service routines
A trap or exception is a software-generated interrupt
caused either by an error or a user request
An operating system is interrupt driven
15
Interrupt Handling
When interrupt occurs
The operating system preserves the state of the
CPU by storing registers and the program counter
Determines which type of interrupt has occurred:
vectored interrupt system
Separate segments of code (Interrupt Handler)
determine what action should be taken for each type
of interrupt
16
Interrupt Timeline
17
Storage Structure
Main memory ( RAM )
Programs must be loaded into RAM to run.
Instructions and data fetched from RAM into registers.
RAM is volatile
"Medium" size and speed
ROM stores relatively static programs E.g. bootstrap
Other electronic ( volatile ) memory is faster, smaller, and more expensive
per bit:
Registers
CPU Cache
Non-volatile memory ( "permanent" storage ) is slower, larger, and less
expensive per bit:
Magnetic disks
Optical disks
Magnetic Tapes
18
Storage Hierarchy
Storage systems organized in hierarchy
Speed
Cost
Volatility
19
Storage-Device Hierarchy
20
Caching
Caching – copying information from slower into faster
storage system;
main memory can be viewed as a cache for secondary
storage
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 is smaller than storage being cached
Cache management important design problem
(Inconsistency management)
Cache size and replacement policy
21
I/O Structure
Large portion of OS code is dedicated to handle I/O
Relevant for system reliability and performance
I/O devices have various natures
A typical I/O operation involves
CPU send I/O request for the controller
The controller examine the request and transfer data to/from local
buffer and device
Send interrupt to OS when data transfer is done
CPU handle the interrupt
This approach has overhead when used for bulk of data
movement
The CPU waste time responding for the interrupts generated for every
byte
22
Direct Memory Access Structure
Used for bulk data movement such as disk I/O.
CPU sets the parameters for the controller
Buffers and pointers
Device controller transfers blocks of data from
buffer storage directly to main memory without
CPU intervention
Only one interrupt is generated per block,
rather than the one interrupt per byte
23
OPERATING SYSTEM
OPERATIONS
24
Operating-System Operations
OS is Interrupt driven (hardware and software)
Hardware interrupt by one of the devices
Software interrupt (exception or trap):
Software error (e.g., division by zero)
Request for operating system service (System Call)
Other process problems include infinite loop, processes
modifying each other or the operating system
25
Operating-System Operations (cont.)
The sytem operate in either user mode or kernel mode
Dual-mode operation allows to
Keep user programs from crashing OS
Keep user programs from crashing each other
CPU mode bit added to computer hardware to indicate current
CPU mode: 0 (kernel) or 1 (user).
When interrupt occurs, CPU hardware switches to kernel
mode.
Switching to user mode (from kernel mode) done by setting
CPU mode bit (by an instruction).
privileged instructions execute only in kernel mode
Exception/Interrupt/Fault
kernel user
Set user mode
26
Transition from User to Kernel Mode
Timer to prevent infinite loop / process hogging resources
Timer is set to interrupt the computer after some time period
Keep a counter that is decremented by the physical clock.
When counter reaches to zero, generate an interrupt
Set up before scheduling process to regain control or terminate
program that exceeds allotted time
27
Major OS tasks
Process management
Memory management
Storage Management
Protection and security
28
Process Management Activities
The operating system is responsible for the following
activities in connection with process management:
Creating and deleting both user and system
processes
Suspending and resuming processes
Providing mechanisms for process synchronization
Providing mechanisms for process communication
Providing mechanisms for deadlock handling
29
Memory Management
To execute a program all (or part) of the instructions must be in
memory
All (or part) of the data that is needed by the program must be
in memory.
Memory management activities
Keeping track of which parts of memory are currently being
used and by whom
Deciding which processes (or parts thereof) and data to move
into and out of memory
Allocating and deallocating memory space as needed
30
Storage Management
OS provides uniform, logical view of information storage
Abstracts physical properties to logical storage unit - file
File-System management
Files usually organized into directories
Access control on most systems to determine who can access
what
OS activities include
Creating and deleting files and directories
Primitives to manipulate files and directories (open, close …)
Mapping files onto secondary storage
Backup files onto stable (non-volatile) storage media
31
Mass-Storage Management
Usually disks used to store data that does not fit in main memory
or data that must be kept for a “long” period of time
Proper management is of central importance
Entire speed of computer operation hinges on disk subsystem and
its algorithms
OS activities
Free-space management
Storage allocation
Disk scheduling
Some storage need not be fast
Tertiary storage includes optical storage, magnetic tape
Still must be managed – by OS or applications
Varies between WORM (write-once, read-many-times) and RW
(read-write)
32
I/O Subsystem
One purpose of OS is to hide peculiarities of hardware
devices from the user
I/O subsystem responsible for
Memory management of I/O including
buffering (storing data temporarily while it is being
transferred),
caching (storing parts of data in faster storage for
performance),
spooling (the overlapping of output of one job with input of
other jobs)
General device-driver interface
Drivers for specific hardware devices
33
Protection and Security
Protection – any mechanism for controlling
access of processes or users to resources
defined by the OS
Security – defense of the system against
internal and external attacks
Huge range, including denial-of-service,
worms, viruses, identity theft, theft of
service
34
OS SERVICES
35
Operating System Services
Operating systems provide an environment for execution of
programs and services to programs and users
The services can be grouped in to two
Functions intended to help users
Services to ensure the operation of the system
itself
1. Functions that are helpful to the user:
User interface - Almost all operating systems have
a user interface (UI).
Varies between Command-Line (CLI), Graphics User
Interface (GUI), Batch
Program execution - The system must be able to
load a program into memory and to run that program,
end execution, either normally or abnormally
(indicating error)
I/O operations - A running program may require 36
Operating System Services (Cont.)
File-system manipulation - The file system is of particular interest.
Programs need to read and write files and directories, create and delete
them, search them, list file Information, permission management.
Communications – Processes may exchange information, on the same
computer or between computers over a network
Communications may be via shared memory or through message
passing (packets moved by the OS)
Error detection – OS needs to be constantly aware of possible errors
May occur in the CPU and memory hardware, in I/O devices, in user
program
For each type of error, OS should take the appropriate action to
ensure correct and consistent computing
Debugging facilities can greatly enhance the user’s and programmer’s
abilities to efficiently use the system
37
Operating System Services (Cont.)
2. OS services for ensuring the efficient operation of the system
itself ( via resource sharing)
Resource allocation - When multiple users or multiple jobs running
concurrently, resources must be allocated to each of them
Many types of resources - CPU cycles, main memory, file
storage, I/O devices.
Accounting - To keep track of which users use how much and what
kinds of computer resources
Protection and security - The owners of information stored in a
multiuser or networked computer system may want to control use of
that information, concurrent processes should not interfere with
each other
Involves ensuring that all access to system resources is
controlled
38
A View of Operating System Services
39
System Calls
Programming interface to the services provided by the
OS
Typically written in a high-level language (C or C++)
Sys calls can be viewed as special function calls
Provides for a controlled entry into the kernel
While in kernel, they perform a privileged operation
Returns to original caller with the result
Mostly accessed by programs via a high-level
Application Programming Interface (API) rather than
direct system call use
A
Three most common APIs are
Win32 API for Windows,
POSIX API for UNIX, Linux, and Mac OS X), and
Java API for the Java virtual machine (JVM)
40
API – System Call – OS Relationship
The system call interface represents the abstract
machine provided by the operating system.
41
Standard C Library Example
C program invoking printf() library call, which calls write() system
call
42
System Call Parameter Passing
Often, more information is required than simple identity of desired
system call
Exact type and amount of information vary according to OS and call
Three general methods used to pass parameters to the OS
Simplest: pass the parameters in registers
In some cases, may be more parameters than registers
Parameters stored in a block, or table, in memory, and address of
block passed as a parameter in a register
This approach taken by Linux and Solaris
Parameters placed, or pushed, onto the stack by the program and
popped off the stack by the operating system
Note that block and stack methods do not limit the number
or length of parameters being passed
43
Examples of Windows and Unix System Calls
44
Operating system Design and Structure
45
Operating System Design and Implementation
Design and Implementation of OS not “solvable”, but
some approaches have proven successful
Internal structure of different Operating Systems can vary
widely
Start the design by defining goals and specifications
Affected by choice of hardware, type of system
User goals and System goals
User goals – operating system should be convenient to use, easy
to learn, reliable, safe, and fast
System goals – operating system should be easy to design,
implement, and maintain, as well as flexible, reliable, error-free,
and efficient
46
Operating System Design and Implementation (Cont.)
Important principle to separate
Policy: What will be done?
Mechanism: How to do it?
Mechanisms determine how to do something, policies
decide what will be done
The separation of policy from mechanism is a very
important principle, it allows maximum flexibility if policy
decisions are to be changed later (example – timer)
Specifying and designing an OS is highly creative task of
software engineering
47
Implementation
Much variation
Early OSes in assembly language
Then system programming languages like Algol, PL/1
Now C, C++
Actually usually a mix of languages
Lowest levels in assembly
Main body in C
Systems programs in C, C++, scripting languages like PERL,
Python, shell scripts
More high-level language easier to port to other
hardware
But slower
48
Operating System Structure
General-purpose OS is very large program, therefore need to be structured
well
Especially, how they structure functionality relative to protection
boundaries.
Various ways
Simple structure (monolithic)
Layered
Microkernel
Module
Hybrid
49
Monolithic/Simple Structure -- MS-DOS
The entire kernel is run as a single
privileged entity .
Functionality can be broken up into modules
but
The modules’ code is highly integrated
Advantage
Utilizes the underlying system efficiently
Disadvantage
Difficult to maintain
MS-DOS is one example
written to provide the most functionality
in the least space
Although MS-DOS has some structure,
its interfaces and levels of functionality
are not well separated
50
Non Simple Structure -- UNIX
UNIX – limited by hardware functionality, the original UNIX operating
system had limited structuring.
The UNIX OS consists of two separable parts
Systems programs
The kernel
Consists of everything below the system-call interface and
above the physical hardware
Provides the file system, CPU scheduling, memory
management, and other operating-system functions; a large
number of functions for one level
51
Traditional UNIX System Structure
Beyond simple but not fully layered
52
Layered Approach
The operating system is divided into a
number of layers (levels), each built on top
of lower layers.
The bottom layer (layer 0), is the hardware;
the highest (layer N) is the user interface.
Each layer provides a different type of
functionality.
With modularity, layers are selected such
that each uses functions (operations) and
services of only lower-level layers
Advantage
Easy for maintenance
Disadvantage
Difficult to modularize the whole OS
Makes OS design very difficult
53
Microkernel System Structure
Moves as much from the kernel into user space
Mach example of microkernel
Mac OS X kernel (Darwin) partly based on Mach
Communication takes place between user modules using message
passing
Benefits:
Easier to extend a microkernel
Easier to port the operating system to new architectures
More reliable and secure (less code is running in kernel mode)
Detriments:
Performance overhead of user space to kernel space communication
54
Microkernel System Structure
55
Modules
Many modern operating systems implement loadable kernel
modules
Uses object-oriented approach
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernel
Overall, similar to layers but with more flexible
Linux, Solaris, etc
56
Solaris Modular Approach
57
Hybrid Systems
Most modern operating systems are actually not one pure model
Hybrid combines multiple approaches to address performance, security,
usability needs
Linux and Solaris kernels in kernel address space, so monolithic, plus
modular for dynamic loading of functionality
Windows mostly monolithic, plus microkernel
Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming
environment
Below is kernel consisting of Mach microkernel and BSD Unix parts, plus
I/O kit and dynamically loadable modules (called kernel extensions)
58
Mac OS X Structure
59
Summary
OS is a system s/w that
Hides complexity of computer hardware
Manages h/w oh behalf of user programs
Has direct privileged access to underlying H/W
Ensures user applications are isolated and protected from
one another
The following are some of the important concepts of
this chapter
Computer system operations
Interrupts,
Major OS tasks
OS services,
System calls,
OS structures
60
End of Chapter One
61