Operating Systems & Memory Management

Download Report

Transcript Operating Systems & Memory Management

Chapter 10: Operating Systems
An operating system is a set of programs through which
a computer manages its resources.
Its main functions are to:
1) Manage the computer hardware
• CPU performance & utilization
• Memory allocation & protection
• Input-output management
• Keyboard control
• Mouse device driver
• Printer spooling
• Display monitor
Applications
I/O Management
Device Drivers
Memory Management
CPU Scheduling
Hardware
Chapter 10
Operating
Systems
Page 110
2) Support application software
Word processors
Electronic spreadsheets
Database management
Computer graphics & games
Chapter 10
Operating
Systems
Page 111
3) Establish a user interface
Textual, with a commandline prompt
Graphical, with windows, menus,
and icons
Chapter 10
Operating
Systems
Page 112
Different Approaches to Processing
Batch Processing
Time-Sharing
Non-interactive execution of one or more
programs with distinct input and output
sessions
Multiple programs executing “simultaneously”
(via time slices) on a single computer (either many
users on a server or one user “multitasking”)
RAM
Process
Process
Process
PCB
PCB
PCB
CPU
Interactive Processing
Multiprocessing
Execution of a program with
additional input from the user and
output to the user during execution
Multiple CPUs available within the computer
system, either across a network or within a
single machine (e.g., a supercomputer)
Chapter 10
Operating
Systems
Page 113
Memory Management
The operating system must coordinate the use of main
memory for any active program on the computer.
When the
program is
compiled, fake
“virtual”
addresses are
used as
placeholders for
the memory
addresses of data
(i.e., variables)
and instructions
(i.e., functions,
loops, and
conditionals).
When the
program is
loaded into RAM,
the virtual
“logical”
addresses are
mapped to actual
“physical”
addresses where
the various parts
of the program
are really stored.
Chapter 10
Operating
Systems
Page 114
Paging
Since multiple programs might be active simultaneously and since
RAM has a limited capacity, large segments of one program’s
memory might be relegated to a backup device to make room for
another program’s memory needs.
Program A’s
Virtual Space
RAM


6

1
4
1


4
4
5

2
7

1


1



3
2
1

1
2
1
2
3
1
3
6

3
7
3
5
1



24
4
6

4
2
2

3

3



3
8


5
2
4

1


2
3
4
Program B’s
Virtual Space
1
2
3
Backup Storage (Disk)
In this example,
when program B is
activated, space in
RAM is made
available by first
“paging out” part
of program A...
...and then “paging
in” program B.
Chapter 10
Operating
Systems
Page 115
CPU Management
Every process executed by the CPU is managed by the
operating system.
New Process
(In a file on
the hard
drive, it
needs to be
loaded into
RAM)
OS “admits”
process by
loading into
RAM
Conceptually, the operating system
moves the process from state to state
in its journey through CPU execution.
Ready
Process
(Loaded into
RAM, it will
run when
allotted CPU
time)
OS “dispatches”
process by allotting
CPU time
OS “interrupts”
process to give another
process CPU time
OS moves process
to ready state when
it’s ready to resume
Waiting
Process
(Needs I/O or
some event
in memory,
temporarily
can’t run)
Running
Process
(In RAM,
with CPU
processing
its
instructions)
OS moves process
to waiting state
when it starts idling
Terminated
Process
(Finished
executing,
its memory
must be
marked
“free”)
OS starts cleaning
up after the process
has completed
CPU Scheduling
When multiple processes are vying for the CPU’s
attention, the operating system must schedule them.
Common Scheduling Options:
Process 1
Process 2
Process
1.1
Process 2
Process 3
Process 1
Process
2.1
Process
3.1
Process 4
Process 4
Process
4.1
Process
1.2
Process 3
Process
2.2
Process
3.2
First-Come First-Served (FCFS)
Disadvantage: Smaller jobs may
have to wait an inordinate
amount of time.
Shortest Job First (SJF)
Disadvantage: Large jobs must
wait until everything else is
finished before starting.
Process
4.2
Process
1.3
Process
3.3
Round Robin
Disadvantage: Processes constantly interrupted when time slices expire.
Process
4.3
Process
3.4
Multilevel Feedback Queue
How do operating systems like Windows and Unix handle
CPU scheduling?
1. Set up several queues, with
processes assigned by their priority
High-Priority
Process 3
High-Priority
Process 2
High-Priority
Process 1
2. The CPU is allotted a certain amount
of time per queue, with longer
amounts for higher priorities.
Mid-Priority
Process 3
Mid-Priority
Process 2
Mid-Priority
Process 1
3. Each process in each queue is given
a specific amount of time to finish.
Low-Priority
Process 3
Low-Priority
Process 2
Low-Priority
Process 1
4. If a process doesn’t finish on time, it’s interrupted and placed at the end of
the next lower priority queue.
5. If a process has to perform an I/O access, it’s placed at the end of its current
queue, so it can resume at the same priority when it reaches the front of the
queue again.
Resource Allocation Poblems
Mutual Exclusion
If two processes require access to the same nonshareable resource at the same time,
then both cannot be accommodated.
Example: Producer & Consumer
Waiting
Producer
Full Queue
Consumer
When extreme cases occur
(either there are no
resources available to be
consumed, or no room for
more to be produced), a
“semaphore” is set to signal
that someone must wait.
Producer
Waiting
Empty Queue
Consumer
Deadlock
If two processes are simultaneously blocking each other’s
progress, then neither one may be able to proceed.
One process copies from the flash to the DVD
One process copies from the DVD to the flash
Chapter 10
Operating
Systems
Page 119