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

Lecture Notes OS 2

The document outlines the fundamental roles and responsibilities of operating systems, including memory and process management, CPU scheduling, and the creation of virtual machines. It distinguishes between application and system software, and discusses various memory management techniques such as fixed and dynamic partitions, as well as paged memory management. Additionally, it covers process management, the process life cycle, and CPU scheduling algorithms.

Uploaded by

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

Lecture Notes OS 2

The document outlines the fundamental roles and responsibilities of operating systems, including memory and process management, CPU scheduling, and the creation of virtual machines. It distinguishes between application and system software, and discusses various memory management techniques such as fixed and dynamic partitions, as well as paged memory management. Additionally, it covers process management, the process life cycle, and CPU scheduling algorithms.

Uploaded by

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

Operating Systems

Chapter Goals (1 of 2)
• Describe the two main responsibilities of an
operating system
• Define memory and process management
• Explain how timesharing creates the virtual
machine illusion
• Explain the relationship between logical and
physical addresses
• Compare and contrast memory management
techniques

2
Chapter Goals (2 of 2)
• Distinguish between fixed and dynamic
partitions
• Define and apply partition selection algorithms
• Explain how demand paging creates the virtual
memory illusion
• Explain the stages and transitions of the process
life cycle
• Explain the processing of various CPU
scheduling algorithms
3
Software Categories
Application Software
Software written to address specific
needs—to solve problems in the real world
System Software
Software that manages a computer system
at a fundamental level

Can you name examples of each?

4
Application software

• Word processing programs


• Games
• Inventory control system
• Automobile diagnostic program
• Missile guidance programs

5
System software

• It provides a convenient environment for program


development and execution. They can be divided
into:
– File management
– Status information
– File modification (text editor)
– Programming-language support (compilers, assemblers,
debuggers and interpreters)
– Program loading and execution (absolute loaders, relocatable
loaders, linkage editors, overlay loaders, debugging systems)
– Communications (send messages, receive messages, browse
web pages, email, transfer files, remote log-on

6
What is an operating system?

• The three most common operating systems


for personal computers are Microsoft
Windows, macOS, and Linux.
• Mobile devices such as phones and tablet
computers are different from desktop and
laptop computers, so they run operating
systems that are designed specifically for
mobile devices. Apple iOS, Google Android
and HarmonyOS.
7
How does OS work?

https://www.youtube.com/watch?v=GjNp0bBrjmU

8
Roles of an Operating System
(1 of 3)

Operating System
System software that:
– Manages computer resources, such as
memory and input/output devices
– Provides an interface through which a human
can interact with the computer
– Allows an application program to interact with
these other system resources

9
Roles of an Operating System
(2 of 3)

What operating
systems have
you used?

An operating system interacts with many


aspects of a computer system

10
Roles of an Operating System
(3 of 3)

The various roles of an operating system


generally revolve around the idea of
“sharing nicely”
An operating system manages resources,
and these resources are often shared in one
way or another among programs that want
to use them

11
Resource Management (1 of 2)
Multiprogramming
The technique of keeping multiple programs that
compete for access to the CPU in main memory at
the same time so that they can execute
OS keeps several jobs in memory at a time. When
one job being executed needs to wait, the OS
switches to and executes another job.
Memory Management
The process of keeping track of what programs are
in memory and where in memory they reside
12
Resource Management (2 of 2)
Process
A program in execution
Process Management
The act of carefully tracking the progress of a
process and all of its intermediate states
CPU Scheduling
Determining which process in memory is executed
by the CPU at any given point

13
Batch Processing
The first operating system was a human operator, who
organized various jobs from multiple users into batches of
jobs that needed the same resources.

In early systems, human operators would organize jobs into batches

14
Timesharing
Timesharing System
A system that allows multiple users to interact with
a computer at the same time
The CPU executes multiple jobs by switching
among them, but the switches occur so frequently
that the users can interact with each program while
it is running.
Virtual Machine
The illusion created by a time-sharing system that
each user has his/her own machine
As computer speed increased, the human
15
operator became the bottleneck.
Virtual Machine

• To abstract the hardware of a single computer


into several different execution environments,
thereby creating the illusion(錯覺) that each
separate execution environment is running its
own private computer
• By using CPU scheduling and virtual-memory
techniques, an OS can create the illusion of
multiple processes, each executing on its own
processor with its own (virtual) memory.

16
Other Factors
• Real-Time System
– A system in which response time is crucial given the nature of
the application

• Response Time
– The time delay between receiving a stimulus and producing a
response
– Amount of time from submission of a request until the first
response is produced
– The amount of time it takes to start responding, not the time it
takes to output the response

• Device Driver
– A small program that “knows” the way a particular device
expects to receive and deliver information

17
Real-Time Systems

• Often used as a control device in a


dedicated application
– such as controlling scientific experiments,
medical imaging systems, industrial control
systems, nuclear reactor, a missile, and some
display systems…

• A real-time system functions correctly


only if it returns the correct result
within its time constraints.
18
Memory Management (1 of 2)
Operating systems must employ techniques to:
– Track where and how a program resides in memory
– Convert logical addresses into actual addresses

Logical Address
Reference to a stored value relative to the program
making the reference
A value specifies a generic location relative to the
program but not to the reality of main memory.
Physical Address
Actual address in main memory
19
Memory Management (2 of 2)

Program 1:
sum is assigned memory
location 23, a location
relative to Program 1

OS must map sum (relative location 23)


to a specific physical address

Logical address for sum (23) is bound to a


physical address in memory before the
Memory is a continuous set of bits program runs
referenced by specific addresses

20
When is a logical address
assigned to a variable?
When the program is compiled.

21
What is address binding?

Address binding is the mapping of a


logical address into a physical address.

When does address binding occur?


When the program is loaded into memory.

22
Single Contiguous MM (1 of 3)

There are only two


programs in memory:
The operating system
The application program

This approach is called


single contiguous
memory management

Main memory divided into two sections

23
Single Contiguous MM (2 of 3)

In concrete terms:
A logical address is simply an integer value
relative to the starting point of the program
A physical address is a logical address
added to the starting location of the program
in main memory

24
Single Contiguous MM (3 of 3)

If A is location 100, and


the application program
is Program 1, then
sum is stored at location
123.

Binding a logical address to a physical address

25
If, in a single contiguous memory management system,
the program is loaded at address 30215, compute the
physical addresses (in decimal) that correspond to the
following logical addresses:
A. 9223
39438

B. 2302
32517

C. 7044
37259

26
Partition Memory Management (1 of 3)
Single contiguous MM has only the OS and one
other program in memory at one time
Partition MM has the OS and any number of other
programs in memory at one time
There are two schemes for dividing up memory for
programs:
– Fixed partitions Main memory is divided into a fixed
number of partitions into which programs can be
loaded
– Dynamic partitions Partitions are created as
needed to fit the programs waiting to be loaded

27
Partition Memory Management (2 of 3)
Memory is divided into a set of partitions, some
empty and some allocated to programs
Base Register
A register that holds the beginning address of the
current partition (the one that is running)
Bounds Register
A register that holds the length of the current
partition

28
Partition Memory Management (3 of 3)

Why check?

Address resolution in partition memory management

29
If, in a fixed partition memory management system, the
current value of the base register is 42993 and the
current value of the bounds register is 2031, compute
the physical addresses that correspond to the following
logical addresses:
A. 104
43097

B. 1755
44748

C. 3041
Address out of bounds of partition

30
Partition Selection Algorithms
(1 of 2)

Which partition should we allocate to a new


program?
• First fit Allocate program to the first partition
big enough to hold it
• Best fit Allocated program to the smallest
partition big enough to hold it
• Worst fit Allocate program to the largest
partition big enough to hold it

Can you give a rationale for each?

31
Partition Selection Algorithms
(2 of 2)

A: 1000 Requests come in for blocks of


the following sizes:
1000, 25, 780, 1600, and 325
B: 700

C: 750 What block will be assigned


to each request if the
• First-fit algorithm is used?
D: 1500 • Best-fit algorithm is used?
• Worst-fit algorithm is used?
E: 300 (Treat each request as an
independent event)
F: 350

32
Example

• Consider three approaches,first fit, best


fit, worst fit, give several memory partitions
,100k, 500k, 200k, 300k, 600k(in order)
and processes, 210k, 410k, 110k, 420k(in
order),

33
Answer

• First fit
– Process
• 210k is allocated to 500k --remainder 290k
• 410k is allocated to 600k --remainder 190k
• 110k is allocated to 290k --remainder 180k
• 420k is not allocated to any free partition

100k 500k 200k 300k 600k

34 NULL
Answer

• Best fit
– Process
• 210k is allocated to 300k --remainder 90k
• 410k is allocated to 500k --remainder 90k
• 110k is allocated to 200k --remainder 90k
• 420k is allocated to 600k –remainder 180k

100k 500k 200k 300k 600k

35 NULL
Answer

• Worst fit
– Process
• 210k is allocated to 600k --remainder 390k
• 410k is allocated to 500k --remainder 90k
• 110k is allocated to 390k –remainder 280k
• 420k is not allocated to any free partition

100k 500k 200k 300k 600k

36 NULL
Paged Memory Management (1 of 6)
Paged Memory Technique
A technique in which processes are divided into fixed-size
pages and stored in memory frames when loaded
Frame
A fixed-size portion of main memory that holds a process
page
Page
A fixed-size portion of a process that is stored into a
memory frame
We assume that a frame and a page are the same size.

37
Paged Memory Management (2 of 6)

Prog. 2, Page 2

Prog. 1, Page 3

If Prog. 1 is running and


needs logical address 2566,
how is the actual address
calculated?

A paged memory management approach

38
Paged Memory Management (3 of 6)
Integer logical address is mapped into a
<page number, offset> logical address
Page Number
Address divided by the page size (say 1024)
Offset
The remainder of the address divided by the page size
2566 DIV 1024 = 2
2566 MOD 1024 = 518 ==> <2, 518>

39
Paged Memory Management (4 of 6)
This new logical
address is mapped to
a physical address with
the help of a page-map
table (PMT)
Every program has a
PMT that shows into
which frame each page
of the program is
stored
What is the physical
address of <2, 518>?
A paged memory management approach

40
Paged Memory Management (5 of 6)

Demand Paging
An extension of paged memory management in
which pages are brought into memory on demand

Page Swap
The act of bringing in a page from secondary
memory, which often causes another page to be
written back to secondary memory

41
Paged Memory Management (6 of 6)

Virtual Memory
The illusion that there are no restrictions on the
size of a program because an entire process
doesn’t have to be in memory at the same time
Thrashing
Inefficient processing caused by constant page
swaps
Relate the expression "all computing is a
tradeoff" to this process.

42
Process Management (1 of 4)

Process Management
The act of managing the use of the CPU by
individual processes
Recall that a process is a program in
execution

What stages does a process go through?

43
Process Management (2 of 4)
The Process States

What can
cause a
process to
move to
the waiting
state?

The process life cycle

44
Process Management (3 of 4)
Process Control Block (PCB)
A data structure used by the OS to manage
information about a process, including:
– Current value of the program counter
– Values of all CPU registers for the process
– Base and bound register values (or page tables)
– Accounting information

Each state is represented by a list of PCBs, one


for each process in that state

45
Process Management (4 of 4)
There is only one CPU and therefore only one set of CPU
registers, which contain the values for the currently
executing process
Each time a process is moved to the running state:
– Register values for the currently running process
are stored into its PCB
– Its PCB is moved to the list of the state into which it goes
– Register values of the new process moving into the running
state are loaded into the CPU
– This exchange of register information is called a context
switch

46
CPU Scheduling (1 of 2)

CPU Scheduling
The act of determining which process in the ready
state should be moved to the running state
– Many processes may be in the ready state
– Only one process can be in the running state, making
progress at any one time

Which one gets to move from ready to running?

47
CPU Scheduling (2 of 2)
Nonpreemptive Scheduling
The currently executing process gives up the CPU
voluntarily
Preemptive Scheduling
The operating system decides to favor another process,
preempting the currently executing process
Turnaround Time
The amount of time between when a process arrives in the
ready state the first time and when it exits the running state
for the last time

48
CPU Scheduling Algorithms
First-Come, First-Served
Processes are moved to the CPU in the order in which they
arrive in the running state
Shortest Job Next
Process with shortest estimated running time in the ready
state is moved into the running state first
Round Robin
Each process runs for a specified time slice and moves
from the running state to the ready state to await its next
turn if not finished

49
First-Come, First-Served

What is the
average turn-
around time?

p1=(0+140)=140, p2=(140+75)=215, p3=(215+320)=535


p4=(535+280)=815, p5=(815+125)=940

50
First-Come, First-Served

What is the
average turn-
around time?

51
Shortest Job Next

What is the
average turn-
around time?

52
Shortest Job Next

What is the
average turn-
around time?

53
Round Robin (1 of 2)

Every process is treated the same!


Time Slice (Quantum)
The amount of time each process receives
before being preempted and returned to the
ready state to allow another process its turn

54
Round Robin (2 of 2)

Suppose the time slice is 50.

What is the average


turnaround time?

55
Round Robin
Suppose the time slice is 50
p1=(50+50*4+50+25+50*3+40)=515
p2=(50+50+50*4+25)=325
p3=(50*2+50+50*3+25+50+50*2+40+50+50+25+50+50
+50+50+50+30+20)=940

p4=(50*3+50+50*2+25+50+50+50+40+50+50+25+50+5
0+50+50+50+30)=920
p5=(50*4+50+50+25+50*2+50+40+50*2+25)=640
What is the average
56 turnaround time?
CPU Scheduling Algorithms

Are these scheduling algorithms preemptive


or nonpreemptive? Explain.

First-Come, First-Served?

Shortest Job Next?

Round Robin?

57

You might also like