0% found this document useful (0 votes)
16 views

Users Run Many Applications Simultaneously: Expect All To Be Running, Doing Work For You

The operating system allows multiple applications to run simultaneously by sharing hardware resources through three main techniques: 1) Managing memory usage by mapping each application's logical address space to physical memory locations, preventing one application from accessing another's memory. 2) Scheduling access to the CPU by allocating processing time to applications and switching between them rapidly, similar to sharing a bathroom between roommates. 3) Protecting each application's data and execution state using processes so that misbehaving applications cannot harm other processes or the operating system.

Uploaded by

Deepanshu Gera
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Users Run Many Applications Simultaneously: Expect All To Be Running, Doing Work For You

The operating system allows multiple applications to run simultaneously by sharing hardware resources through three main techniques: 1) Managing memory usage by mapping each application's logical address space to physical memory locations, preventing one application from accessing another's memory. 2) Scheduling access to the CPU by allocating processing time to applications and switching between them rapidly, similar to sharing a bathroom between roommates. 3) Protecting each application's data and execution state using processes so that misbehaving applications cannot harm other processes or the operating system.

Uploaded by

Deepanshu Gera
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

11/1/10

UNIVERSITY of WISCONSIN-MADISON
Computer Sciences Department
Users Run Many Applications
CS 202 Professor Andrea Arpaci-Dusseau Simultaneously
Introduction to Computation Fall 2010

Lecture 25:
How does a computer…
"
run many applications simultaneously?

Expect all to be running, doing work for you…

Today’s Mystery What is an Operating System?


How does computer run multiple applications on
one set of hardware? Users
Any Scratch Program
Word processor
Applications Web browsers
•  CPU : processing unit (ALU + set of registers) and
control unit (program counter) Operating System
•  Random Access Memory CPU
Hardware Memory
•  Input/output devices I/O devices

Operating System (OS):


How are applications going to share? Software that converts hardware into a useful form for
many different applications
Very complex: millions of lines of code, 1000 person-years

1  
11/1/10  

How does OS help applications


Roommate Scenario
share hardware? Imagine two roommates sharing
double dorm room (1 bath)
OS gives each application illusion that it is only one
running on hardware What properties must hold to
be as if they have own room?
Manage hardware resources for applications •  Other person doesn’t vandalize
their stuff
What do you think the OS must provide? •  Other person doesn’t look
through their personal stuff
•  Can use bathroom whenever you
need
Some properties about
•  Protecting your stuff
•  Getting to do what you want

How does this match Computer? Terminology


Multiple applications sharing same hardware OS executes “processes” not applications
•  An application may be composed of multiple
processes
General Requirements
•  Protecting your stuff = Protecting data that resides in Memory
•  Getting to do what you want = Running on CPU when you want
What is a process?
Specifics "Execution stream (i.e., instructions) in
context of process state (i.e., data)
•  No vandalism of stuff = Another app can’t overwrite your data
•  What you want to do, plus your stuff
•  Can’t look through stuff = Another app can’t read your data
•  Can use bathroom when needed = Run on CPU when app has work
to do (not when sleeping) Find processing by running “ps” (Unix-based)
Must handle misbehaving apps – Before harm occurs •  More processes running than you might expect!
•  What if roommate won’t leave bathroom????
•  Must have way to remove them against their will!

2  
11/1/10  

Terminology Hardware Resources


Multi-programming: Multiple processes resident in memory
at same time 1) How to share memory?
•  Same as multi-tasking
Opposite: Uni-programming 2) How to share CPU?
•  Only one process resident at a time
•  Examples: First systems and DOS for PCs
Not multiprocessing: Multiple processors
Advantages: Better user convenience and performance
•  Why does it improve performance???

Challenges with
How to Share Memory?
Sharing Memory
Illusion provided by Operating System?
•  Each process has all of physical memory to itself
1) Ensure one process cannot r/w another process’s
memory
Reality: Reside in physical memory at same time
•  OS and HW cooperate to implement protection
Technique: Space sharing –  Translate memory references from logical to physical addresses
Physical View

Physical View
Process 1 Process 1

Process 3 Process 3
Process 2 Process 2
Logical View of Address Space Logical View of Address Space
Everything process can address thru memory including data and code Everything process can address thru memory including data and code

3  
11/1/10  

Challenges with
How to Share CPU?
Sharing Memory
2) Not enough physical memory for all address spaces Process alternates btwn CPU and I/O
•  What policy should OS use to determine what •  I/O: wait for user input
is kept in memory and what is not? •  Analogy: Alternate btwn bathroom and bedroom
Time sharing: Switch quickly between processes

Physical View
OS and HW together perform context switch
•  Change contents of registers and Program Counter (PC)
–  Stored in memory when not running (only OS can read this memory)
•  Change active address space in memory
Process 1 –  One process should not be able to read data of another process!

Perform context switches at different points


Process 3
•  When one job waits for I/O, switch to new job
Process 2
Logical View of Address Space
•  When one job has been using CPU too long, switch
Everything process can address thru memory including data and code –  Prevents one process from hogging CPU

Example:
How to Share CPU?
Service at a Deli
If only one wants CPU, no problem Many customers waiting for service at deli…
In what order should customers be handled?
What do you do if multiple processes want CPU at
same time?

OS must also implement policy


•  Many processes want to run, but which should run
when??

4  
11/1/10  

Easiest Policy? Different Requirements?


First-come-first-served (FCFS) 1) Some costumers have a deadline
How to implement this policy?
•  Customers take ticket when arrive, serve next number
•  Customers add to end of line, serve next customer in line
2) Some customers are more important than others

Why do you think this a good policy?


•  Easy to implement
•  Intuitively Fair: Earlier you arrive, sooner you get service
3) Some costumers have short orders, others very long
orders
Why could it be bad?
•  Treats all customers identically but may have different requirements

1) Scheduler for Handling…


Earliest Deadline First
Deadlines?
Earliest Deadline First In Computer Systems?
•  Ask everyone when need to be done by •  Used for “real time” and “embedded” applications
•  Serve costumer with next deadline (search for min!) Control system must periodically perform different
Examples in Real World? tasks
•  Check different sensors (temp, speed, location, battery life)
•  Sometimes in long lines for airline check-in
•  Adjust different controls (rotation, power)
What is good?
How to determine deadlines?
•  Everyone finishes by when they need to •  Every task needs to run periodically at same interval
What is bad about this approach? •  Next deadline = last time ran + interval
•  Not fair: Works best when everyone works together •  Some sensors and controls more important than others
•  Needs knowledge and trust: When is your real deadline? –  Check/control them more frequently…
•  Impossibility: Might not be able to meet all deadlines

5  
11/1/10  

2) Scheduler for Handling…


Priority Scheduling
Important Customers?
Priority-based scheduling In Computer Systems…
•  Allow important customers to move to front of line
Which processes should be given high priority?
Examples in real life?
•  First-class in airlines, Fast Pass at Amusement Parks
Advantages? Give higher priority to system processes
•  Give fastest service to most important customers (make them •  Responsible for keeping machine running
happiest)
Disadvantages?
•  Less important customers can starve Give higher priority to “interactive” processes
–  Might never receive service if many important customers keep arriving •  Processes user is currently “interacting” with
–  Extreme of “unfair” –  Give priority to which process they are typing to
•  Determining who is “important” can be difficult –  Give priority to which process is creating output
–  Spend the most money? Influence the most other people? Angriest?

3) Scheduler for Handling… Big Idea:


Short Jobs? Use Past to Predict Future
“Shortest Job First” (SJF)
•  Figure out which customer has shortest order
Processes behave in future similarly to past
•  Let shortest orders go to front of line (search!) (just like people?)
Examples in Real World? •  Did this process use CPU for small time in the past?
•  Decide to interrupt counter person with question…
•  Use info to schedule short CPU bursts
•  Separate lines for “10 items or less”
Advantages
•  Creates optimal schedule for average waiting time Remember: Process alternates btwn CPU and I/O
–  Minimizes average waiting time over all customers
–  Moving short job before long job:
(e.g., wait for user input)
•  Improvement in wait time of short job > Penalty to long job
Disadvantages
•  Costumers with many items can starve; unfair
•  How can you tell how length of job will take? Incentive to lie!
–  Must solve for this to work in computer systems!
–  How???

6  
11/1/10  

Details: Implementation in OS Today’s Summary


Multi-level feedback queue Operating System: Software that manages hardware
•  Multi-level queue: •  Provides illusion to each process that it’s only one running
–  Context switches CPU across processes (Time share)
N lists of different priorities
–  Protects memory across processes (Space share)
•  Feedback: •  Scheduling policies for CPU:
Move to queue based on length of –  First-come-first-served (FCFS), Earliest-deadline-first,
last CPU burst Priority-based, Shortest-Job-First (SJF)
–  Use past behavior to approx SJF: Multi-level Feedback Queue
Reading
•  Section 6.4 of Invitation to CS
OS runs process at highest (priority) queue
•  Processes in same queue scheduled Round Robin
Announcements
–  Switch out jobs hogging CPU
•  HW 6 due before class Friday: Lists in Scratch
•  Can also fix starvation problem by moving up processes
not scheduled for awhile…

7  

You might also like