Vous êtes sur la page 1sur 62

Operating Systems

August- December 2010


Instructors

• Sanjay Gupta
• Rajeev Shorey

Guest Lectures
• Dr. Sorav Bansal, CSE Department, IIT Delhi
• Possibly others
Useful Details
• Textbook
– Operating System Concepts, 8th edition, by Silberschatz, Galvin and
Gagne
– OS by Andrew Tanenbaum
– OS by William Stallings
• Revised Class Timings
– Prefer two classes of one and a half hour each
– Monday
• Lab: 2:30 – 4:30 PM
• Class: 4:30 – 6:00 PM
– Wednesday
• Class: 3:30 – 5:30 PM
• Time slot for Doubts/Clarifications
• We will keep a one hour time slot per week to clarify doubts from
students
Useful Web Sites
UNIX Guru Universe: Excellent source of UNIX information.
Linux Documentation Project: The name describes the site.
Windows Development: Good source of information on Windows internals. Note especially the section on
Windows Base Services.
The comp.os.research FAQ: Lengthy and worthwhile FAQ covering operating system design issues.
ACM Special Interest Group on Operating Systems. Information on SIGOPS publications and conferences.
IEEE Technical Committee on Operating Systems and Applications. Includes an online newsletter and links to
other sites.
IEEE Computer Society Task Force on Cluster Computing An international forum to promote cluster computing
research and education.
Beowulf Central soure of information on Beowulf clusters..
The Memory Management Reference A good source of documents and links on all aspects of memory
management.
The Operating System Resource Center A useful collection of documents and papers on a wide range of OS
topics.
Operating System Technical Comparison Includes a substantial amount of information on a variety of
operating systems.
Review of Operating Systems A comprehensive review of commerical, free, research and hobby OSs.
I/O Characterization and Optimization A facility dedicated to education and research in the area of I/O design
and performance. Useful tools and tutorials. Operated by the U. of Illinois.
Object Management Group Industry consortium that promotes CORBA and related object technologies.
Grading: Weightage

• Mid Terms and End Semester Exam: 50%


• Assignments: 20%
• Lab work/Programming Assignments: 30%
Course Topics

• Introduction & Terminology


– Examples of Operating Systems
– History
• Threads & Processes
• Concurrency & Synchronization
• Scheduling
• Virtual Memory
• I/O
• Disks, File systems, Network file systems
• Protection & Security
Course Goals

• Introduce you to operating system concepts


• Cover important systems concepts in general
– Caching, concurrency, memory management, I/O,
protection
• Teach you to deal with large software systems
– Several Programming assignments
– Warning: This course will probably be your heaviest this
semester
• Prepare you for advanced systems courses
– Advanced topics, recent developments
– Communication Networks
– Real-time Operating Systems
Why Study Operating Systems?
• Operating systems are a maturing field
– Most people use a handful of mature OSes
– Hard to get people to switch operating systems
– Hard to have impact with a new OS
• High-performance servers are an OS issue
– Face many of the same issues as OSes
• Resource consumption is an OS issue
– Battery life, radio spectrum, etc.
• Security is an OS issue
– Hard to achieve security without a solid foundation
• Scalability is an OS issue
– Large server farms need to solve hard OS problems
• New “smart” devices need new Oses
– Palm Pilot
– Apple iPod, iPAD
Key Reason: Why Study OS?
• Foundation Course
• Several advanced concepts (e.g., Networking,
Real Time Systems, …) need background of OS
• Fascinating area
• Major challenges

• Learn to enjoy the course !


A Peek at History
IBM Model 701 (Early 1950's)
IBM 7094 (Early 1960's)
IBM System 360 Console
IBM 7094 (Early 1960's)
IBM 701 Console

CS 140 Lecture Notes: Introduction


OS Evolution: From Mainframes to iPod
What is an OS?

• Software between applications and reality


– abstracts hardware and makes portable
– makes finite into (near)infinite
– provides protection
Operating System
A View of Operating Systems Services

User and Other System Programs

GUI Batch Command Line

User Interfaces

System Calls
H
Program I/O File Resource
Communication Accounting
Execution Operation Systems Allocation
Error Protection &
Detection SERVICES Security
Operating System
Hardware
Focus of this Course
Terminology

• Concurrency
• Multitasking, Time Sharing, Processor Sharing
• Multiprocessing
• Multithreading
• Multiprogramming
• Context Switching
• Thrashing
• …
Abstraction
• What if? The entire software stack was one giant event-driven
loop
– Possible, BUT clumsy
– Certainly not practical for general purpose computers
• Better way:
– Separate software into layers of abstraction
• e.g., OS -> JVM -> Java bytecode
– All programs are written (or compiled) to the abstraction
provided by the OS
• Abstractions may be different for different OS’es
– e.g., Windows program will not run on Linux even
though same underlying hardware
Operating System: System View
• An OS is a Resource Allocator
• Examples of Resources
– CPU Time
– Memory space
– File-Storage space
– I/O devices
• OS acts as a Manager of these resources
• OS faces numerous and possibly conflicting requests
for resources
• OS must decide how to allocate the requests to specific
programs and users
– Challenge: Need to operate the Computer System
“Efficiently” and “Fairly”
Question
• What do you mean by “efficiently”?
• What do you mean by “fairly”?
Operating Systems Structure
• Let’s understand Multiprogramming and Time Sharing
• Multiprogramming
– The Key idea is to keep the CPU busy most of the times
– CPU is an important resource and should not idle

Operating System

Job 1 Waiting for Task


(I/O Operation)
Job 2

Job 3

Job 4
Take Away
• Multiprogrammed systems provide an
environment in which various systems
resources are utilized effectively, but they do
not provide for user interaction with the
computer system
Time Sharing or Processor Sharing
or Multitasking

Processor
Job Queue or
Server

Arriving Jobs or Tasks Job Departures

Quantum (δ)

Question: What happens when δ 0 ?


Time Sharing or Multitasking

• Logical extension of Multiprogramming


• Key Idea
– CPU executes multiple jobs by switching among
them
– Switches occur so frequently that the users can
interact with each program while it is running
– A Time shared OS uses CPU scheduling and
multiprogramming to provide each user with a
small portion of time-shared computer
What is Middleware?
Middleware
• Software that provides a link between
separate software applications
• Middleware is sometimes called plumbing
– It connects two applications and passes data
between them
• Middleware allows data contained in one
database to be accessed through another
Terminology

• Concurrency
• Multitasking
• Multiprocessing
• Multithreading
• Multiprogramming
• Context Switching
• Thrashing
• …
Example:
CPU Scheduling (is Fun)
Scenario #1
Ready Queue
C B A
2ms 1ms 100ms

FCFS
Avg:
A B C
101.3
time 100 101 103

Round Robin
Avg:
A B C A C A
36.7
time 2 5 103
Scenario #2
Ready Queue
C B A
10ms 10ms 10ms

FCFS
Avg:
A B C
20
time 10 20 30

Round Robin
A B C A B C ... A B C A B C
Avg:
29
time 28 29 30
Scenario #1
Ready Queue
C B A
2ms 1ms 100ms

FCFS
Avg:
A B C
101.3
time 100 101 103
Round Robin
Avg:
A B C A C A
36.7
time 2 5 103
STCF
Avg:
B C A
35.7
1 3 103
Scenario #2
Ready Queue
C B A
10ms 10ms 10ms

FCFS
Avg:
A B C
20
time 10 20 30
Round Robin
A B C A B C ... A B C A B C
Avg:
29
time 28 29 30
STCF
Avg:
A B C
20
time 10 20 30
Next Class
• Topics that we will cover
– High Level Overview – to begin with !
– Process Management
– Memory Management
– Storage Management
– Protection & Security
– Distributed Systems
– Special Purpose Systems
Lessons Learned
• Resources in Computer and Communication
Systems are always finite
– Computer Systems: Operating Systems
• Question: What are some of the resources?
– Communication Systems: Networks
• Question: What are some of the resources?
• Resources “Cost”, nothing is free !
• Therefore, we need to “Optimize” Resource
Consumption
More Terminology
• Efficiency
• Fairness
• Speedup
• Throughput
• Scalability
• Reliability
• Fault-Tolerance
• Availability
• …
Efficiency
• Fraction of time a resource is busy or utilized
• Example:
– CPU is busy 96% of time
– Efficiency is .96
Fairness
• Fairness can be defined in several ways
– Proportional fairness
– Max-Min fairness

Resource

Bandwidth
or
CPU

TIME
Speedup
• A term used in Parallel Processing heavily
• Suppose
– T_1: Time taken on a Uniprocessor
– T_N: Time taken on a Multiprocessor with N
nodes
• Then,

Speedup = T_1 / T_N


Throughput
• Term used in Networking & Communications
• Number of bits/second or packets/second that
have reached destination

• Question: What is “Goodput”?


Scalability
• An application scales when it works for a large
number of nodes
• Example:
– My simulation program works well with 10 nodes
– If it works well with even with thousands of
nodes, then the program/simulation program
scales well !
More Terminology !
• Let’s understand
– Job Scheduling
– CPU Scheduling
– Swapping
– Virtual Memory
– Physical Memory
– Trap/Exception
–…
Job Scheduling
• Time Sharing Systems
– Several jobs are kept simultaneously in Memory
– System must fetch K out of N jobs to the Memory
1

Operating System

Job 1 Waiting for Task


N Jobs (I/O Operation)
Job 2
Memory Size: K
Job 3

Job K N>K
N
CPU Scheduling

Processor
or
Server

Arriving Jobs or Tasks Job Departures

Question: What job should the Server choose next?


THIS IS “CPU SCHEDULING”.
One of your Assignment will be in this Topic !
Memory
• Swapping
– Processes are swapped in and out of main
memory to the disk
– Why?
• To ensure a reasonable response time
• Virtual Memory vs Physical Memory
– VM enables users to run programs that are larger
than PM
– Allows execution of a process that is not
completely in Memory
Trap or Exception
• A software-generated interrupt caused by
– Error (e.g., Division by zero)
– Specific request from a user program that an OS
service be performed
• ISR
– Interrupt Service Routine is provided that is
responsible for dealing with the interrupt
OS: Dual-Mode Operation
Transition from User to Kernel Mode

User Process
User Process Return from User Mode
Calls System Call Mode Bit = 1
Executing System Call

TRAP TRAP
Kernel Mode bit = 0 Mode bit = 1 Kernel Mode
Execute System Mode Bit = 0
Call

Kernel Mode: Supervisor Mode, System Mode or Privileged Mode


Timer
• A Timer can be set to interrupt the computer
after a specified period
• Period could be “fixed” or “variable”
• Timers are implemented by Counters
• Counters decrement every delta unit time
• When Counter < 0
– OS terminates the program for exceeding the
assigned time limit
Processes and Threads
What is the “Process”?
• Each user has at least one separate program in
memory
• A program loaded into memory and executing
is called a Process
Process
• "An execution stream in the context of a
particular process state"
– Execution stream
• A sequence of instructions (only one thing happens at a
time)
– Process state
• Everything that can affect, or be affected by, the process:
code, data, call stack, open files, network connections, etc.
• Is a process the same as a program?
• Virtually all modern operating systems are
multiprogramming systems: multiple processes
can exist simultaneously and share the machine
Process
• What is the difference between a Program and
a Process?
– Program: a Passive entity
– Process: an Active entity
• With a PC and a set of associated resources
What are “Threads”
• Most modern operating systems also support threads:
multiple execution streams within a single process
– Threads share process state such as memory, open files,
etc
– Each thread has a separate stack for procedure calls (in
shared memory)
– Thread is unit of sequential execution
• Why support threads?
– Concurrent execution on multiprocessors
– Manage I/O more efficiently: some threads wait for I/O
while others compute
– Most common usage for threads: large server applications
Process Concept
• What does a Stack contain?
– Temporary data
• Example: Function parameters, return addresses, local
variables, …
• Heap
– Memory that is dynamically allocated during
process run time
• Data section: global variables
Process State
Process being created Process has finished
execution

Instructions are being


executed
The Process is waiting
to be assigned to a
processor

Waiting The Process is waiting for


some event to occur
Process State
Process Control Block (PCB)

The state information must be saved when an interrupt occurs, to allow the process
to be continued later
Process Scheduling: Queueing Diagram
Representation

Termination

Question: what happens when a process is terminated?

Vous aimerez peut-être aussi