Os - Lecture - Complete (w1+2)
Os - Lecture - Complete (w1+2)
2
What is an Operating System ?
An operating
OS as a course?
system
To provide an
is a program that
introduction to
acts as an
operating systems;
intermediary
what they do, how
between a user of
they are used, and
a computer and
how they are
the
implemented
computer
hardware.
4
Course Contents
Computer and operating system structures
Process and thread management
Process scheduling
Resource management
Process synchronization and communication
Memory management
Virtual memory management
Deadlock management
5
How will this course work?
6
Course Structure
Lectures (Three in a week)–Tuesday & Wednesday
Lab sessions (One in a week) -
Individual and/or group assignments (Plagiarism policy)
Default due date is: before or during the first lecture of the
week
Quizzes (Announced and Unannounced)
Midterm (7th or 8th week)
End term exam
And, off course, 75% attendance is mandatory to sit
in the final exam, as per Riphah policy.
7
Material
Lecture Notes
Lab Hand-outs
Recommended Books
Operating System Concepts
Essentials, by Abraham Silberschatz,
Peter B. Galvin, & Greg Gagne
(9th Edition)
8
Online Resources (Course home page)
http://vle.riphah.edu.pk
Check at least twice per week!
Lecture notes, Lab hand-outs, Attendance
etc.
12
What is an Operating System?
An interface between users and hardware - an
environment "architecture”
Allows convenient usage; hides the tedious
stuff
Allows efficient usage; parallel activity, avoids
wasted cycles
Provides information protection
Gives each user a slice of the resources
Acts as a control program.
13
Operating System
14
Computer System Structure
Computer system can be divided into four
components:
Hardware – provides basic computing resources
i.e. CPU, memory, I/O devices
Operating system – Controls and coordinates
use of hardware among various applications and
users
Application programs – define the ways in
which the system resources are used to solve the
computing problems of the users
Word processors, compilers, web browsers,
database systems, video games
Users – i.e. People, machines, etc.
15
OPERATING SYSTEM The Layers Of
OVERVIEW A System
Humans
Program Interface
User Programs
O.S. Interface
O.S.
Hardware Interface/
Privileged Instructions
Disk/Tape/Memory
16
Operating System Definition
OS is a resource allocator
Manages all resources
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
17
Operating System Definition (Cont.)
No universally accepted definition
18
What Operating Systems Do?
Depends on the point of view
Users want convenience, ease of use
Don’t care about resource utilization
Shared computers such as mainframe or
minicomputer must keep all users happy
Users of dedicate systems such as
workstations have dedicated resources but
frequently use shared resources from servers
Handheld computers are resource poor,
optimized for usability and battery life
Some computers have little or no user
interface,
such as embedded computers in devices and
19 automobiles
OPERATING SYSTEM
Components
OVERVIEW
The CPU is wasted if a job waits for I/O. This leads to:
22
Batch Processing (Mainframe Systems)
• Executing a series of noninteractive jobs all at one time.
• The term originated in the days when users entered
programs on punch cards.
• System operator, feed them into the computer
• The user cannot interact with the job when it is executing
The user must set up the control cards to handle all
possible outcomes
• In a batch system, programs cannot be debugged. A
programmer cannot modify a program as it executes to
study its behavior
• No Interactive Development
23
Mainframes: Batch processing [source IBM]
27
Time-Sharing Systems–Interactive Computing
30
Parallel Systems (Cont.)
Symmetric multiprocessing (SMP)
Each processor runs an identical copy of the operating
system.
Many processes can run at once without performance
deterioration.
Most modern operating systems support SMP
UNIX
SUNOS Version 5 (Solaris2)
Asymmetric multiprocessing
Each processor is assigned a specific task; master
processor schedules and allocated work to slave
processors.
More common in extremely large systems
SUNOS Version 4
31
Symmetric Multiprocessing Architecture
32
A Dual-Core Design
33
Distributed Systems
Distribute the computation among several
physical processors.
Loosely coupled system – each processor
has its own local memory; processors
communicate with one another through
various communication lines, such as
high-speed buses or telephone lines.
Advantages of distributed systems.
Resources Sharing
Computation speed up – load sharing
Reliability
Communications
34
Distributed Systems (cont)
Requires networking infrastructure.
Local area networks (LAN) or Wide area
networks (WAN)
May be either client-server or peer-to-
peer systems.
35
General Structure of Client-Server
36
Peer-to-Peer Computing
Another model of distributed system
P2P does not distinguish clients and servers
Instead all nodes are considered peers
May each act as client, server or both
Node must join P2P network
Registers its service with central lookup service on
network, or
Broadcast request for service and respond to requests
for service via discovery protocol
Examples include Napster and Gnutella
37
Clustered Systems
Clustering allows two or more systems to
share storage closely linked via a local area
network.
Provides high reliability.
Asymmetric Cluster (at least two servers: One
is on a standby mode while the other is
monitoring the other one. If one stops other
will work).
Symmetric clustering: all N hosts are running
the application. They work together and
monitor each other)
38
Clustered Systems
39
Special-Purpose Systems
Real-time embedded systems are much
prevalent form of computers
Vary considerably, special purpose, limited
purpose OS, real-time OS
Multimedia systems
Streams of data must be delivered according to
time restrictions
Handheld systems
PDAs, smart phones with limited CPU, memory,
power
Reduced feature set OS, limited I/O
40
Real-Time Systems
Often used as a control device in a
dedicated application such as
controlling scientific experiments,
medical imaging systems, industrial
control systems, and some display
systems.
Well-defined fixed-time constraints.
Real-Time systems may be either hard
or soft real-time.
41
Handheld Systems
Personal Digital Assistants (PDAs)
Cellular telephones
Issues:
Limited memory
Slow processors
Small display screens.
PALM OS
Packet PC OS
42
Open-Source Operating Systems
Operating systems made available in source-code
format rather than just binary closed-source
Counter to the copy protection and Digital
Rights Management (DRM) movement
Started by Free Software Foundation (FSF),
which has “copyleft” GNU Public License (GPL)
Examples include GNU/Linux and BSD UNIX
(including core of Mac OS X), and many more
43
OS Installation Methods
44
Computer Startup
bootstrap program is loaded at power-up or
reboot
Typically stored in ROM or EEPROM, generally
known as firmware
Initializes all aspects of system
Locate and Loads operating system kernel into
memory
OS then starts its first process “init” and wait for
some event to occur
Occurrence of event is usually signaled with an
interrupt
Either from Hardware or Software
46
Computer System Organization
Computer-system operation
One or more CPUs, device controllers, Memory
connected through common bus
Concurrent execution on CPUs
Devices competing for memory cycles
47
Computer-System Operation
I/O devices & CPU 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 of devices
I/O is from the device to the local buffer
Device controller informs CPU that it has
finished its operation by using interrupts
48
Common Functions of Interrupts
Interrupt transfers control to the interrupt
service routine
through the interrupt vector, that contains
addresses of all the service routines
Must save the address of interrupted
instruction
Interrupt handling may be Sequential or
Nested
49
Interrupt Handling
Operating system preserves the state of the
CPU by storing values of registers and
program counter
For Context Switching
Then it determines which type of interrupt has
occurred
Separate segments of code determine what
action should be taken for each type of
interrupt
50
I/O Structure
Computers normally contain CPUs and Device
Controllers connected with Buses
Each device controller is in charge of specific
type of device
More than one devices can be attached to single
device controller
Device controller maintains a Local Buffer and a
set of special purpose registers
Device controller is responsible for data movement
between Peripheral device and local buffer
OS has a Device Driver for each device
controller
51
I/O Structure
52
Direct Memory Access (DMA) Structure
Used for high-speed I/O devices
Transmit information at close to memory
speeds
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
Useful for bulk data transfer
CPU can perform other tasks during this time
53
Storage Structure
Main memory – large storage media that CPU
can access directly, volatile
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
Disk controller determines the logical interaction
between device and computer
54
Storage Hierarchy
Storage system is organized in hierarchy that
depends upon:
Speed
Cost
Volatility
55
Caching
Important principle, performed at many levels in a
computer (in hardware, operating system,
software, web servers)
Information in use is copied from slower to faster
storage temporarily
First the faster storage (cache) is checked to
determine if information is there
If found, information used directly from the cache (fast)
If not, data copied to cache and then used
56
Storage-Device Hierarchy
57
How a Modern Computer Works
A von Neumann
architecture
58
Computer-System Architecture
Most systems use a single general-purpose
processor
Systems also have special-purpose processors
Multiprocessors systems are growing in use
Also known as parallel systems, tightly-coupled
systems
Advantages:
1. Increased throughput
2. Economy of scale
3. Increased reliability – graceful degradation or fault
tolerance
Two types of multiprocessor systems:
1. Asymmetric Multiprocessing (Client/Server)
2. Symmetric Multiprocessing (Peers)
59
Operating-System Operations
Interrupts are mainly driven by hardware
Software interrupts create exception or trap
Division by zero, request for unauthorized memory
Infinite loop, processes modifying each other or the
operating system
60
Operating-System Operations
A special Mode-bit provided by hardware
Provides ability to distinguish when system is running
user code or kernel code
Some instructions designated as privileged,
executable only in kernel mode
System call changes user mode to kernel mode, and
return from call resets it to the user mode
61
Timer
Timer to prevent infinite loop / process
monopolizing resources
Set interrupt after specific period
Operating system decrements counter
When counter gets zero interrupt is generated
Set up before scheduling process to regain control
or terminate program that exceeds allotted time
62
Process Management
A process is a program in execution
It is a unit of work within the system
Program is a passive entity
process is an active entity
Process needs resources to accomplish its task
CPU, memory, I/O, files
Initialization data
Process termination requires reclaim of any
reusable resources
63
Process Management
Single-threaded process has one program
counter
Specifying location of next instruction to execute
Process executes instructions sequentially, one at
a time, until completion
Multi-threaded process has one program
counter per thread
Typically system has many processes, some
user, some operating system running
concurrently on one or more CPUs
Concurrency by multiplexing the CPUs among the
processes / threads
64
Process Management Activities
OS performs following activities for 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
65
Memory Management
All data and instructions must be in memory
in order to execute
Memory management determines what is in
memory for optimizing CPU utilization and
response time to users
Memory management activities
Keeping track of which parts of memory are
currently being used and by whom
Deciding which processes (or part of process) and
data to move into and out of memory
Allocating and deallocating memory space as
needed
66
Storage Management
OS provides uniform, logical view of
information storage
Abstracts physical properties of storage devices to
define a logical storage unit i.e. file
File is a collection of related information
defined by its owner
Files are stored on medias with varying
properties
Access speed, capacity, data-transfer rate, access
method
OS maintains the File Management System
67
Storage Management
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
Mapping files onto secondary storage
Backup files onto secondary storage
68
Mass-Storage Management
Usually disks are used to store data for a long
period of time
Entire speed of computer operations may depend
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
69
Performance of Various Levels of Storage
Movement between levels of storage
hierarchy can be explicit or implicit
70
Migration of Integer A from Disk to Register
71
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 of security attacks, including denial-of-service,
worms, viruses, identity theft, theft of service
Systems generally first distinguish among users, to
determine who can do what
User identities (user IDs, security IDs) include name and
associated number, one per user
Group identifier (group ID) allows set of users to be defined for
control management, then also associate group with each
process and file
Privilege escalation allows user to change to effective ID with
more rights
72
Interrupts, Traps and Signals
73
Challanges of Time sharing systems
74