You are on page 1of 59

1

ER/CORP/CRS/OS94 ER/CORP/CRS/OS94 Ver. No.: 1.0 Ver. No.: 1.0 Copyright 2008, Infosys Technologies Ltd. Copyright 2008, Infosys Technologies Ltd.
Education and Research
We enable you to leverage knowledge anytime, anywhere!
Confidential Confidential
I
n
f
o
s
y
s
Operating System Concepts
Operating System Concepts
Part -1
Part -1
Welcome to this course on Operating System Concepts
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
General Guideline
General Guideline
(2008) Infosys Technologies Ltd.
This document contains valuable confidential and proprietary information of Infosys. Such
confidential and proprietary information includes, amongst others, proprietary intellectual
property which can be legally protected and commercialized. Such information is furnished
herein for training purposes only. Except with the express prior written permission of Infosys,
this document and the information contained herein may not be published, disclosed, or used
for any other purpose.
2 2
2
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Confidential Information
Confidential Information
This Document is confidential to Infosys Technologies Limited. This document
contains information and data that Infosys considers confidential and proprietary
(Confidential Information).
Confidential Information includes, but is not limited to, the following:
Corporate and Infrastructure information about Infosys
Infosys project management and quality processes
Project experiences provided included as illustrative case studies
Any disclosure of Confidential Information to, or use of it by a third party, will be
damaging to Infosys.
Ownership of all Infosys Confidential Information, no matter in what media it resides,
remains with Infosys.
Confidential information in this document shall not be disclosed, duplicated or used
in whole or in part for any purpose other than reading without specific written
permission of an authorized representative of Infosys.
This document also contains third party confidential and proprietary information.
Such third party information has been included by Infosys after receiving due written
permissions and authorizations from the party/ies. Such third party confidential and
proprietary information shall not be disclosed, duplicated or used in whole or in part
for any purpose other than reading without specific written permission of an
authorized representative of Infosys.
3 3
3
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Learning approach
Learning approach
The following are strongly suggested for a better learning and
understanding of this course:
Noting down the key concepts in the class, explained by the educator
Analyze all the examples / code snippets provided
Study and understand the self study topics
Completion and submission of all the assignments, on time
Completion of the self review questions in the lab guide
Study and understand all the artifacts including the reference materials / e-
learning / supplementary materials specified
Completion of the project (if applicable for this course) on time inclusive of
individual and group activities
Taking part in the self assessment activities
Participation in the doubt clearing sessions
4 4
4
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Course Prerequisite
Course Prerequisite
Knowledge of Basic computer Hardware
Introduction to computer system
5 5
6
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
6 6
Course Objectives
Course Objectives
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Learning Outcomes
Learning Outcomes
Basic understanding of OS
Understanding of Memory management functions of operating
system.
Concept of Paging and Virtual memory
Understanding of Process states and Process scheduling
policies.
Understanding of Interprocess communication , Producer
Consumer problem and Critical section.
Understanding of Basic File concept & File management
Understanding of Device management and data transfer
using DMA.
7 7
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Course Agenda
Course Agenda
Part 1
Introduction to OS course and Scope of the subject
Basic OS concept :
Goals and Major Functions of Operating System.
Multiprogramming ,Multitasking & Multiprocessing
Memory Management schemes
Simple Paging
Demand Paging
Page Replacements Algorithms
Segmentation
Paged Segmentation
Process Management
Process Definition
Process State Transition
Process Control Block
8 8
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Course Agenda
Course Agenda
Part 2
Process Management
Process Scheduling
Preemptive scheduling
Non Pre-emptive scheduling
Threads
Interprocess Communication
Concurrency
Critical Section problem
Mutual Exclusion
Semaphore
9 9
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Course Agenda
Course Agenda
10 10
11
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
11 11
References
References
Silberschatz and Galvin, Operating System Concepts, John
Wiley & Sons ,Sixth edition
Andrew Tanenbaum, Modern Operating Systems, Pearson
Education
Milan Milenkovic, Operating Systems: concepts and design,
McGraw-Hill
Charles Crowley, Operating Systems: A Design-Oriented
Approach
D.A. Patterson and J.L. Hennessy, Computer Architecture: A
Quantitative Approach, 2nd edition, Morgan-Kaufmann, 1996.
12
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
12 12
Session Plan Part 1
Session Plan Part 1
Introduction to OS course and Scope of the subject
Basic OS concept :
Goals and Major Functions of Operating System.
Multiprogramming ,Multitasking & Multiprocessing
Memory Management schemes
Paging
Segmentation
Paged Segmentation
Page Replacements Algorithms
Process Management
Process Definition
Process State Transition
Process Control Block
13
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
13 13
Operating System
Operating System
System Software which acts as an interface between the user
and the computer
It provides an environment to execute different types of
applications
It is viewed as a Resource Allocator or Resource Manager
Memory
Processor(s)
Peripherals
Information
Operating System is a set of system programs which provides an environment to help the
user to execute the programs. The OS is a resource manager which allocates and manages
various resources like processor(s), main memory, input/output devices and information
(files) on secondary memory devices.
The primary goal of Operating System is to provide the execution environment for the
system programs and application programs.
Secondary Goal of Operating System is to manage and allocate the system resources
efficiently to various applications running in the system.
Resource Examples Managers
Memory Primary, Secondary Memory Management
Processors CPU, I/O Process Management
Peripherals Terminal, Printer, Tape Device Management
Information Files, Data File Management
Examples:
WINDOWS XP
WINDOWS VISTA
LINUX
UNIX
OS/ 2
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Operating system as an interface
Operating system as an interface
14 14
Files
Processor
Operating System
System Software which acts as an interface between the user and the computer.
It provides an environment to execute different types of applications
It is viewed as a Resource Allocator or Resource Manager
Memory
Processors
Peripherals
Information
14
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Major Functions of Operating System
Major Functions of Operating System
Memory Management
Process Management & CPU scheduling
Interprocess Communication
File management
Device and I/O Management
15 15
15
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
16 16
Layers of Computer System
Computer Hardware
Operating System
System & Application Programs
User 1 User n User 2
.
Application
program e.g.
Calculator,
Notepad etc.
System
program e.g
C Compiler etc.
Database
application e.g
Oracle etc.

Operating System is a set of system programs which provides an


environment to help the user to execute the programs.
16
17
ER/CORP/CRS/OS94 ER/CORP/CRS/OS94 Ver. No.: 1.0 Ver. No.: 1.0 Copyright 2008, Infosys Technologies Ltd. Copyright 2008, Infosys Technologies Ltd.
Education and Research
We enable you to leverage knowledge anytime, anywhere!
Confidential Confidential
I
n
f
o
s
y
s
Operating System : Terminology
Operating System : Terminology
Introduction to Operating Systems
Introduction to the Concepts of Memory Management
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
18 18
Uni-programming
Uni-programming
User Program
Area
OS
Job1
Only one job resides in the memory at any time
Observations?
1.CPU utilization
2.Memory utilization
unused
In sequential program execution/ Uniprogramming , only one program/job at a time
can reside in main memory.
CPU execute this program. When program is busy in I/O CPU sits idle for that time.
18
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Multiprogramming
Multiprogramming
More than one job resides in main memory
Multiple users can access the system simultaneously
19 19
User Program
Area
OS
Job1
Job2
Other jobs
can be stored
Observations?
19
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Multiprocessing
Multiprocessing
More than one processor executes one or more jobs in
parallel
20 20
CPU1 CPU n CPU2

Memory
20
21
ER/CORP/CRS/OS94 ER/CORP/CRS/OS94 Ver. No.: 1.0 Ver. No.: 1.0 Copyright 2008, Infosys Technologies Ltd. Copyright 2008, Infosys Technologies Ltd.
Education and Research
We enable you to leverage knowledge anytime, anywhere!
Confidential Confidential
I
n
f
o
s
y
s
Memory Management
Memory Management
Introduction to Operating Systems
Introduction to the Concepts of Memory Management
22
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
22 22
Memory Management
Memory Management
Manages memory usage efficiently
Allocates memory to as many user jobs as possible
Respond to changes in memory demand by user jobs
Prevent unauthorized changes to a user jobs memory
The computer must keep several processes in memory at the same time to improve the
CPU utilization and the speed of the response of the computer to its users. Memory
management discusses various ways to manage memory.
23
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
23 23
Memory Management Schemes
Memory Management Schemes
Simple Paged allocation
Demand Paging
Segmentation
Paged Segmentation
There are various memory management schemes as mentioned in the slide
above. Each scheme has its own advantage and disadvantage. Selection of
a particular technique depends on various factors such as hardware support,
extent of memory available etc.
Logical address is the address generated by the CPU and the range of these
addresses is called Address Space/ User Dddress Space.
Where as physical address is the actual address of the process in the main memory
and the range of these addresses is called Memory Space /Physical Address Space .
24
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
24 24
Simple Paged Allocation
Simple Paged Allocation
All pages for a job should reside in memory
Divides the jobs address space into pages of the same size
Divides the main memory address space into blocks/frames
Pages are units of memory that are swapped in and out of
primary memory
Pages are grouped together for a given user job and are placed
in page tables
Simple paged allocation is a solution to fragmentation.
Advantage:
As each page is separately allocated, the users job need not be contiguous.
Disadvantages:
Extra memory required for storing page tables
Considerable amount of hardware support is required for address
transformations etc.
All pages of entire job must be in memory
25
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
25 25
Simple Paged Allocation
Simple Paged Allocation
Page 0
Page 1
Page 2
Job A
Memory Space
Frame 1
Frame 2
Frame 3
Free Frame Frame 4
Frame 5
Free Frame Frame 6
Frame 7
Free Frame Frame 8
Page 0
Page 1
Job B A
-
0
A
-
1
A
-
2
B
- 0
B
-
1
Frame 0 Free Frame
The example in the slide above shows a page map table for 2 jobs viz., page
number and frame number which essentially shows the mapping between
page number and block number. JOBA has 3 pages viz., 0,1,2. Page 0
maps to frame 5 in the OS, page 1 to frame 3 and page 2 to frame 1 in the
OS. JOB 2 has page 0 in frame 2 and page1 in frame7.
Thus, we can see that pages of a job need not be located contiguously in the
memory.
26
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
26 26
Page Table and Address Translation
Page Table and Address Translation

f
An address in jobs address space is considered to be of the form(p,d) where
p is the page number containing the memory location and d is the
displacement (offset) of the memory location from the start of the page. This
page number acts as index to a page table which is created for every job.
This page table gives the corresponding frame number in the main memory
for the particular page. This frame number with the displacement would give
the physical address.
The Page table has two purposes:
It has got entries which map each page number in the program (in the
secondary memory) and the corresponding page frame number (or block
number present in the primary memory).
Since there is one to one mapping between the page number and the frame
number , even if the pages are not contiguous in the primary memory, there
exists a link between all the pages of a job through this mapping in the page
table.
27
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
27 27
Internal Fragmentation due to Simple
Paged Allocation
Internal Fragmentation due to Simple
Paged Allocation
Page size=4K
Fragmentation is wastage of memory, it occurs when memory is divided in to
many small chunks/free blocks and these free blocks are not able to satisfy any
request. Fragmentation is of two type: 1. Internal fragmentation 2. External
fragmentation
Internal Fragmentation: As shown in the diagram in this slide, internal
fragmentation is wastage of the space inside the allocated memory blocks.
Because page size / memory block is of fixed size. Job may need less space but
minimum 1 memory block is allocated(space allocated to a job is always multiple of
frame) , so the wastage of memory happens is internal fragmentation. Limitation
because of fixed size memory block.
External Fragmentation: Memory that is not allocated to any job but still
unusable because it is divided in to small chunks. These chunks are too small to
satisfy the request of any job.
28
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
28 28
Illusion of infinite memory available to the user (Virtual Memory)
Job operating under demand paging
A page is brought to the main memory only when there is a
demand
Demand Paging
Demand Paging
29
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
29 29
Demand Paging
Demand Paging
Page number Frame number
JOB 1
2 3 1 0
Status
1000
2000
3000
4000
7000
OS
Page Table
Modify
The diagram in the slide above shows the page map table for demand paging. The
page map table (PMT) has two additional columns viz., status and modify or
judgment. Initially, all the pages have status field as NA (Not Available) implying
that all the pages are in the secondary device (disk). As and when a page is loaded
from the secondary to primary, the status is updated to A (Available) from NA. Now,
if the same page is required again in the main memory, the status bit will indicate
the presence of it in the primary memory. The judgment field decides if a page has
to be moved back to the secondary memory or not.
1000, 2000, 3000 are the frame starting addresses
30
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
30 30
Page Replacement
Page Replacement
Suppose a scenario when all frames in memory are full and a
Page Fault occurs.
We need to bring in the required page but there in no free frame.
where we will load it?
31
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
31 31
Page Replacement Algorithms
Page Replacement Algorithms
Algorithms used for page replacement are
First in First out (FIFO )
Least Recently Used ( LRU )
Least Frequently Used (LFU)
Not Recently Used (NRU ) (Discussed in Appendix)
Most Recently Used (MRU) (Discussed in Appendix)
Most Frequently Used (MFU ) (Discussed in Appendix)
Page Fault: If a user job accesses a page and the page is not available in the main memory,
a page fault is said to occur
Page Replacement: If the memory is full then the inactive pages which are not needed
currently for execution are removed and are replaced by those pages from the secondary
device which are to be executed. This is called Page Replacement.
FIFO: If the algorithm decides that the page has been first moved to the memory should be
moved out to secondary memory first, then it is using FIFO.
LRU: If the algorithm decides to move a page from main memory and store it in secondary
memory based on the fact that it is not used often in the recent times, then it is called LRU.
For every page a timestamp is maintained in the judgment field.
LFU: If the algorithm decides to move a page from main memory and store it in secondary
memory based on the fact that it is not used often, then it is called LFU. For every page a
reference counter is maintained in the judgment field.
NRU: If the algorithm decides to move a page from main memory and store it in secondary
memory based on the fact that it is not used at all in the recent times, then it is called NRU.
A reference bit is associated with each page.
MRU: If the page which has been used recently will be replaced by the incoming page.
MFU: This technique replaces the page which is used most frequently
Demand Paging technique could lead to a scenario where in a job might try to access a
particular page which is not available in main memory. This would lead to a fault called
page fault. Consider the figure discussed in slide 34 (All frames are already occupied),
suppose that the page 2 of job A, which is currently in memory, tries to access page 1 of job
A then a page fault would occur because page 1 is not loaded in memory. Once this page
fault is caused the OS would replace one of the existing pages in physical memory with
page 1 of job A . the process of removing some pages from physical memory to
accommodate new pages is called Page Replacement.
32
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
32 32
Page Replacement Algorithms
Page Replacement Algorithms
Page request sequence
3 1 3 4 2 4 1 2 3 1 2 4 2 3 1 3
FIFO (Assume frame size 3 and No frames preloaded)

Number of page faults=10
Number of page replacement = 7
33
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
33 33
Page Replacement Algorithms
Page Replacement Algorithms
Page request sequence
3 1 3 4 2 4 1 2 3 1 2 4 2 3 1 3
LRU

Number of Page faults=9
34
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
34 34
Page Replacement Algorithms
Page Replacement Algorithms
Page request sequence
3 1 3 4 2 4 1 2 3 1 2 4 2 3 1 3
LFU (use FIFO in case of tie)

Number of Page faults=9
Ask the participants to solve the problem using LFU with LRU technique instead of FIFO.
Another variation could be not to reset the counter even as a page is swapped out.
Refer to the examples in the course material for more examples on different types of page
replacement algorithms.
35
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
35 35
Segmentation
Segmentation
Segment is a grouping of information that is treated as a logical
entity
A process is divided into different segments each of its own
length.
Example: one segment can correspond to a single subroutine or a
group of closely related subroutines
Segmentation uses unequal chunks
Each individual segment can be protected
Segmentation support the user view of memory
In paging , job is divided into fixed length pages , it does not provide support to user view of
memory.
User view of memory means , user like to see job is divided into variable length segments.
For example, a program consist of main program , one or more then functions/ subroutines
etc. Each of these modules are referred to by a name and each of these segments may be
of different length. The length of each segment is calculated from the code written in the
segment or from the logical structure of the program.
Thus segmentation supports the user view of memory. A programmer has a say on the
number of segments in a process and this division is dependent on the logical structure of
the process.
36
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
36 36
Segmentation
Segmentation
2
(Segment 2)
24
(24 Bytes)
Segment No. (s) Displacement (d)
s
2048 Bytes
(2K)
20480
8192 Bytes
(8K)
11264
4096 Bytes
(4K)
1024
Length Byte Address
0
1
2
Segment Table
Is d > length
1048
1024
Memory
Error
Yes
No
Byte address + the
displacement gives the
physical address
37
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
37 37
Paged Segmentation
Paged Segmentation
Requires two-level translation : Segment tables to page tables
and then to main memory
Paging leads to internal fragmentation
Segmentation leads to external fragmentation
Trying to reduce external fragmentation increases internal
fragmentation and vice versa
In practice most operating systems use the combination of paging
and segmentation. This is called as Paged Segmentation
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
38 38
Logical address space of a process is divided into three parts
Segment Number(S)
Page Number(P)
Offset(d)
Intel 386 and later architecture use segmentation with paging
Paged Segmentation
Paged Segmentation
38
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
39 39
+
+
Segment Table
Page Table
Main Memory
Frame
Number
Offset
Segment
Number
Page
Number
Page
Frame
d
Virtual/Logical Address
Segment Map
Table
Segment
Number
Page
Number
Offset
Paged Segmentation
Paged Segmentation
Suppose a process references a virtual/logical address V=(S, P, d) ,then a search will
be performed to locate (S,P). There are three possibilities for it
(i)If (S,P) found in associative storage then , we fine page frame and then move as
per offset to get real memory address.
(ii)If (S,P) is not found in associative storage then we should follow these steps
(i) Find base address b of segment map table ( in primary memory)
(ii) Add b to segment number S ( Say we set S1)
(iii) Then we add S1 to P to get frame number
(iv) Finally we add offset d to get real memory address.
(iii)If segment map table indicates that segment S is not in primary memory, a
segment fault is generated
39
40
ER/CORP/CRS/OS94 ER/CORP/CRS/OS94 Ver. No.: 1.0 Ver. No.: 1.0 Copyright 2008, Infosys Technologies Ltd. Copyright 2008, Infosys Technologies Ltd.
Education and Research
We enable you to leverage knowledge anytime, anywhere!
Confidential Confidential
I
n
f
o
s
y
s
Process Management
Process Management
41
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
41 41
Process Management
Process Management
Processor
Hardware component that is capable of executing
instructions
Process
An instance of a program in execution
Is an active entity whereas a program is a passive entity
Needs certain resources for execution in which a
processor is one of them
The computer system today allows multiple programs to be loaded into memory and to be executed
concurrently but at one point of time only one program is in execution or rather at most one instruction
is executed on behalf of the process.
A source program stored on disk is called passive because it will not demand any resource.
A process is an active entity i.e. program in execution is called process during execution process
demand resource like CPU , memory , I/O etc. for the execution.
42
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Why Process Management
Why Process Management
The four applications are to be served by one processor
OS allocates the processor to each application one at a time
This is done by the process management module of OS
42
MS Outlook Calculator
IE MS Word
User wants to work with more than one application.
Operating System
User feels that all of them run simultaneously, however operating system allocates
one process at a time.
43
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
43 43
States of a Process
States of a Process
New : Created
Ready : Assign a process to a processor
Run : Instruction execution
Blocked : For an event to occur (Ex: I/O)
Terminated : Finished execution
Here, the instructor must draw the state diagram in a piecemeal fashion slowly adding the complexity
and inviting more questions.
New Here the operating system recognizes the process but does not assign resources to it.
Ready The process is ready/waiting to be assigned to a processor.
Run When a process is selected by the CPU for execution, it moves to the run state.
Blocked When a process is waiting for some event to occur, say for e.g I/O completion or reception
of a signal then it is in the blocked state i.e. when a running process does not have immediate access
to a resource it is said to be in the blocked state.
Terminated This is the state reached when the process finishes execution.
44 44
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
44 44
Process State Diagram
Process State Diagram
New
Ready
Waiting
Terminated
Running
Admitted
Exit
IO or Event
wait(Blocked)
Interrupt
I/O or Event
Completion
Processor
Allocated
Here, the instructor must draw the state diagram in a piecemeal fashion
slowly adding the complexity and inviting more questions.
New Here the operating system recognizes the process but does not
assign resources to it.
Ready The process is ready and waiting for the processor for execution.
Run When a process is selected by the CPU for execution, it moves to the
run state.
Blocked When a running process does not have immediate access to a
resource it is said to be in the blocked state.
Terminated This is the state reached when the process finishes
execution.
45
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
Process Management
Process Management
Includes :
Creating and terminating processes
Controlling and saving the state of a process
Acting on exceptional conditions during process execution
(Interrupts)
Communication among processes
45
46
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
46 46
Context Switching
Context Switching
The task of switching the CPU from one process to another
process.
Context switching
Keeps the CPU busy all the time
Occurs when any of the following situations is encountered
An I/O operation is initiated
An interrupt occurs
An I/O is completed
A process terminates
Context switching is a overhead as the system does not do any useful work while switching from one
process to another. switching speed varies from machine to machine depends upon the memory
speed, the no. of registers to be copied etc.
Since at any point of time there could be more than one process waiting to be serviced by the CPU,
these have to be put in hold at some place. A queue is a place where the IN and OUT of the process
is controlled. There are different queues for different purposes.
Example:
I/O Queue If the process is waiting for an I/O operation to complete, then it goes to the I/O queue.
Job queue A process entering the system for the first time goes into the Job queue.
47
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
47 47
Process Control Block
Process Control Block
Structure in the Operating System which keeps track of the
status of the process.
Process id
Process State
Program Counter value for the process
Register information
Accounting information
Memory information for the process
List of open files, Inter Process communication Information
Pointers to the PCB of the next process to run
47 47
Process Control Block
Process Control Block
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
48 48
Brainstorming
Brainstorming
Suppose one process is under execution, if a high priority job arrives,
what decision OS will take?
What are the various possibilities?
Suppose one process is under execution, if a high priority job arrives,
what decision OS will take?
What are the various possibilities?
Suppose four applications(Calculator, Outlook, MS Word & Internet
Explorer) are to be served by one Processor ,OS allocates the
processor to each application one at a time.
How OS will allocate Processor to each application one at a time?
What will be the order of execution?
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
49 49
Can you answer these questions?
Can you answer these questions?
What is Operating System ? What are the functions of
Operating System?
What do you mean by Frame?
Which data structure is used to convert logical address to
physical address?
Virtual address is address of hard Disk(TRUE/FALSE).
What is the difference between Internal and External
Fragmentation?
Interrupt change the state of process from _________ to
_______ state?
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
50 50
Self Study
Self Study
Memory Managements Techniques.
51
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
51 51
Summary
Summary
Operating System
Memory Management
Memory management Schemes
Paging
Segmentation
Paged Segmentation
Process Management
Process Definition
Process State Transition
Process Control Block
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
52 52
Thank You
The contents of this document are proprietary and confidential to Infosys Technologies Ltd. and may not be
Disklosed in whole or in part at any time, to any third party without the prior written consent of
Infosys Technologies Ltd.
2008 Infosys Technologies Ltd. All rights reserved. Copyright in the whole and any part of this document
belongs to Infosys Technologies Ltd. This work may not be used, sold, transferred, adapted, abridged, copied or
reproduced in whole or in part, in any manner or form, or in any media, without the prior written consent of
Infosys Technologies Ltd.
52
53
ER/CORP/CRS/OS94 ER/CORP/CRS/OS94 Ver. No.: 1.0 Ver. No.: 1.0 Copyright 2008, Infosys Technologies Ltd. Copyright 2008, Infosys Technologies Ltd.
Education and Research
We enable you to leverage knowledge anytime, anywhere!
Confidential Confidential
I
n
f
o
s
y
s
Page Replacement Techniques
Page Replacement Techniques
Appendix 1
Appendix 1
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
54 54
Page Replacement Techniques
Page Replacement Techniques
In demand paging whenever page fault occurs and if free slot
is also not available, we have to replace an existing page with
the required page.
For selecting the page which will be moved out we different
techniques. Some of them are
FIFO (First in First Out) (Discussed in slide)
LFU (Least Frequently Used) (Discussed in slide)
LRU (Least Recently Used) (Discussed in slide)
NRU (Not Recently Used)
MRU(Most Recently Used)
MFU (Most Frequently Used)
54
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
55 55
Not Recently Used (NRU)
Not Recently Used (NRU)
NRU page replacement algorithm allow the pages to reside in
the memory that have been recently used
When replacement required it select the not recently used
page for the replacement
When a page is referenced by the CPU, a referenced bit is set
for that page
After fixed time interval, the referenced bit of all the pages are
cleared, so only pages reffered within the current clock interval
are marked with a referenced bit.
When a page needs to be replaced, One page is selected
randomly from the pages for which reference bit is not set.
55
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
56 56
Most Recently Used (MRU)
Most Recently Used (MRU)
The page which has been used recently will be replaced by the
incoming page.
Example
Consider a dynamic paging scheme, where the page numbers
and request sequence is as follows:
1 1 3 1 1 6 4 2 3 7 2 5 6 4 3 4 2 7 6
Given that the total number of frames in the memory is 4 and that
the first two frames are loaded with pages 1 and 3, calculate the
number of page faults that occur when the MRU algorithm is
used.
56
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
57 57
Solution
Solution
1 1 3 1 1 6 4 2 3 7 2 5 6 4 3 4 2 7 6
1
3
1
3
1
3
1
3
1
3
1
3
6
1
3
6
4
1
3
6
2
1
3
6
2
1
7
6
2
1
7
6
2
1
7
6
5
1
7
6
5
1
7
4
5
1
7
3
5
1
7
4
5
1
7
2
5
1
7
2
5
1
6
2
5
No. of page faults : 10
No. of page replacements : 8 (For first two page faults page will not
be replaced)
57
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
58 58
Most Frequently Used (MFU)
Most Frequently Used (MFU)
This technique replaces the page which is used most frequently
With each page we can attach one page reference count and when ever page
replacement is required we will select the page in memory having
maximum count
To resolve any tie we use FIFO
Most of the time it does not give good performance
Example
Consider a dynamic paging scheme, where the page numbers and request
sequence is as follows:
1 1 3 1 1 6 4 2 3 7 2 5 6 4 3 4 2 7 6
Given that the total number of frames in the memory is 4 and that the first
two frames are loaded with pages 1 and 3, calculate the number of page
faults that occur when the MFU algorithm is used (Use FIFO for resolving
any tie and do not reset the counter whenever a page is replaced).
58
Copyright 2008, Infosys Technologies Ltd.
Confidential
I
n
f
o
s
y
s
59 59
Solution
Solution
59