You are on page 1of 100

SACHIN G.

PAWAR
SUNBEAM, PUNE.
What is Operating System:
 An OS is a program that manages the computer
hardware.
 It also provides a basis for application programs
and acts as an intermediary between the
computer user and the computer hardware.
 OS is a resource allocator: Resources like, CPU
time, memory space, file storage space, I/O
devices and so on.
 OS is the control program: manages the execution
of user programs to prevent errors and improper
use of computer.
 The One program running all the time on
computers is the Kernel, everything else is
either as system program (ships with the OS)
or an application programs.

CD/DVD : Core OS + Programs/Utilities


Core OS : Kernel
 The procedure of starting a computer system
by loading the kernel is known as booting
process.
 The first sector of any device/partition is
known as boot sector.
 If boot sector of any storage device/partition
contains a special program called bootstrap
program, then that device is said to be
bootable device/partition.
 Bootstrap program locates the kernel, loads it
into main memory and starts its execution.
 There is separate bootstrap program for each
OS.
 If multiple operating systems are installed on
the computer, the boot loader encompasses the
boot strap/boot loader for other operating
systems.
 NTLDR(Windows), GRUB(Linux), Boot
Mgr(Windows 7 and Windows 8)
 A Computer is a complex system;
contemporary computers contains millions of
elementary electronics components.

Basic functions of Computer:


1. Data Storage
2. Data Processing
3. Data Movement
4. Control
 Basic structural Components of the Computer
System:
The way in which the components are interrelated.
1. Central Processing Unit/Processor: Controls the
operations of computer and performs its data
processing functions.
2. Main Memory: Stores instructions and data
3. I/O: Moves data between the computer and its
external environment.
4. System interconnections: Some mechanism that
provides for communication among CPU, main
memory, and I/O.
 Word: In general word is an ordered set of bytes
or bits(binary digit) that is the normal unit in
which information may be stored, transmitted or
operated within on within a given computer.
 The basic elements of digital computer, must
perform data storage, movement, processing and
control functions. Only two fundamental types of
components required.
1. Gates: is a device that implements a simple
Boolean or logical function, such as AND, OR
functions.
2. Memory Cell: is a device that can store one bit
of data; i.e. the device can be in one of two
stable states at any time.

 By interconnecting large numbers of these


fundamental devices we can construct a
computer.
Top level view of computer components:
1. CPU:

PC, IR, MAR, MBR, I/O AR, I/O BR,


Execution Unit.
2. I/O module:

Buffers
3. Main memory:

Instructions, Data
4. System Bus
 When data are moved over longer distances, to or
from a remote device, the process is known as
communications.
 Bus: A bus is communication pathway connecting
two or more devices. A key characteristic of bus is
that it is shared transmission medium.
 Multiple devices connects to bus, and a signal
transmitted by any one device is available for
reception by all other devices attached to the bus.
 Typically bus consists of multiple communication
pathways or lines, each line is capable of
transmitting signals representing binary 1 and
binary 0.
 System Bus: A bus that connects major computer
components (processor, memory, I/O) is called
system bus.
 There are many different bus designs, on any bus
the lines can be classified into three functional
groups:
1. Data lines (data bus)
2. Address lines(address bus)
3. Control lines
Typical control lines includes:
Memory write, Memory read, I/O write, I/O read,
Transfer ACK, Bus request, Bus grant, Interrupt
request, Interrupt ACK, Clock and Reset.
Internal Memory:
1. Processor registers

2. Cache Memory/One or more levels of Cache:


L1, L2.
3. Main Memory(Dynamic Random Access
Memory).
External Memory:
1. Hard disk

2. Magnetic disk

3. Optical disks and tapes


Characteristics of Memory System:
1. Location
Processor
Internal (main memory)
External (secondary)
2. Capacity
Word size
Number of words
3. Unit of transfer
Word
Block
4. Access Method
1. Sequential
2. Direct
3. Random
4. Associative
5. Performance
1. Access Time(latency)
2. Memory Cycle Time: The minimum time delay
between the initiation of two independent memory
operations is called Memory cycle time.
3. Transfer rate
6. Physical Type
Semi conductor
Magnetic
Optical
Magneto-optical
7. Physical Characteristics
Volatile/non volatile
Erasable/non erasable
8. Organization
Cache Memory:
It is used between CPU and Main memory to
increase the overall system performance.
Disk Cache:
It is purely a software technique. A portion of
main memory can be used as buffer to hold
data temporarily that is to be read out to disk.
Such a technique some times referred as disk
cache, which improves performance.
 The cache contains a copy of portions of main
memory.

 When the processor attempts to read a word of


memory, a check is made to determine if the
word is in the cache. If so, the word is
delivered to the processor. If not a block of
main memory consisting of some fixed number
of words, is read into the cache and then word
is delivered to the processor.
 Main memory consists of up to 2^n addressable
words, with each word having a unique n-bit
address.
 Memory is considered to consists of number of
fixed-length blocks of K words each, i.e. there are
M = 2^n/K blocks.
 The Cache consists of C lines. Each line contains K
words, plus a tag of few bits; the number of words
in the line is referred to as line size.
 The number of lines is considerably less than the
number of main memory blocks.(C << M)
 The tag is usually a portion of the main memory
address.
 When a cache hit occurs, the data and address
buffers are disabled and communication is only
between processor and cache with no system
bus traffic.
 When a cache miss occurs, the desired address
is loaded onto the system bus and the data are
returned through the data buffer to both the
cache and the processor.
Main Memory/RAM(Random Access Memory)
 The two basic forms of semiconductor random
access memory are:
1. Dynamic RAM
2. Static RAM.
 The basic element of main memory is memory
cell.
 DRAM and SRAM

Synchronous DRAM, Rambus DRAM, DDR


SDRAM, Cache DRAM
Types of ROM (Read Only Memory)
PROM: Programmable ROM
Three forms of Read Mostly memory:
1. EPROM: Erasable Programmable ROM
2. EEPROM: Electrically Erasable
Programmable ROM
3. Flash Memory.

UV EPROM: Ultra Violetically Erasable


Programmable ROM.
Magnetic Disk:
 Magnetic disks remain the most important
component of external memory. Both removable
and fixed, or hard, disks are used in systems
ranging from personal computers to mainframe
and supercomputers.
 To achieve greater performance and higher
availability, servers and larger systems use RAID
disk technology.
 RAID is a family of techniques for using multiple
disks as a parallel array of data storage devices,
with redundancy built into compensate for disk
failure.
 Tracks: On the circular platter the set of concentric
rings are called as tracks.
 Each track is the same width as the head. There are
thousands of tracks per surface.
 Adjacent tracks are separated by gaps. These
prevents or at least minimizes, errors due to
misalignment of the head or simply interference of
magnetic fields.
 Sectors: Data are transferred to and from the disk
in sectors. There are typically hundreds of sectors
per track, and these may be of either fixed or
variable length .
 To avoid imposing unreasonable precision
requirements on the system, adjacent sectors
are separated by intra track (inter sector) gaps.
Physical Characteristics of Disk Systems
1. Head Motion:

Fixed head(one per track)


Movable head(one per surface)
2. Platters:
Single Platter
Multiple Platter
3. Disk Portability:
Non removable disk
Removable disk
4. Sides:
Single sided
Double sided
5. Head Mechanism:
Contact (Floppy)
Fixed gap
Aerodynamic gap (Winchester)
Disk Performance Parameters:
1. Seek Time: On a movable head system, the
time it takes to position the head at the track is
known as seek time.
2. Rotational Delay: once the track is selected,
the disk controller waits until the appropriate
sector rotates to line up with the head. The time
it takes for the beginning of the sector to reach
the head is known as Rotational Delay or
Rotational Latency.
3. Access Time: The sum of seek time if any
and the rotational delay is equals the access
time, which is the time it takes to get into the
position to read or write.
4. Transfer Time: Once the head is in position,
the read and write operation is then performed
as the sector moves under the head, this is the
data transfer portion of the operation; the time
required for the transfer is the transfer time.
RAID( Redundant Array of Independent Disks)
1. RAID is a set of physical disk drives viewed
by the operating system as a single logical
drive.
2. Data are distributed across the physical drives
of an array.
3. Redundant disk capacity is used to store parity
information, which guarantees data
recoverability in case of disk failure.
I/O Module:
 In addition to the processor and set of memory
modules, the third key element of a computer
system is a set of I/O modules.
 Each module interfaces to the system bus or
central switch and controls one or more
peripheral devices.
 I/O module contains the logic for performing a
communication function between the
peripheral and the bus.
Major functions of I/O Modules:
1. Interface to the processor and memory via the system
bus or central switch.
2. Interface to the one or more peripheral devices by
tailored data links.

 An external device attaches to the computer by a link


to an I/O module.
 The link is used to exchange control, status, and data
between the I/O module and the external device.
 An external device connected to an I/O module is
often referred as peripheral device and or peripheral.
We can broadly classify external devices into
three categories:
1. Human readable: suitable for
communicating with the computer user.
e.g. VDT’s Video Display Terminals and
Printers.
2. Machine readable: suitable for
communicating with equipment. e.g. magnetic
disks and tape systems.
3. Communication: suitable for communicating
with remote devices.
 To execute an I/O related instructions, the
processor issues an address specifying particular
I/O module and external device.

 There are four types of I/O commands that an I/O


module may receive when it is addressed by the
processor.
1. Control
2. Test
3. Read
4. Write
Nature of an external device:
1. The interface to I/O module is in the form of
control, data and status signals.
2. Control signals determines the function that the
device will perform, such as send data to the I/O
module (INPUT or READ), accept data from the
I/O module (OUTPUT or WRITE), report status,
or perform some control function particular to the
device (e.g. position a disk head).
3. Data are in the form of set of bits sent or receive
from the I/O module.
4. Status signals indicates the state of the device.
E.g. READY/NOT READY.
Control Logic associated with the device,
control’s the device operation in response to
direction from the I/O module.
The Transducer: converts data from electrical
to other forms of energy during output and
from other forms to electrical during input.
 With Programmed I/O, data are exchanged
between the processor and the I/O module.
The Processor executes a program that gives it
direct control of the I/O operation, including
sensing device status, sending a read or write
command, and transferring the data.
 When the processor issues the command to the
I/O module, it must wait until the I/O
operation is complete. If the processor is faster
than the I/O module, this is wasteful processor
time.
 With Interrupt driven I/O, the processor issues an
I/O command, continue to execute other
instructions, and is interrupted by the I/O module
when the later has completed its work.
 With both Programmed and Interrupt driven I/O,
the processor is responsible for extracting data
from main memory for output and storing data in
main memory for input.
 The alternative knows as Direct Memory
Access(DMA), in this mode, the I/O module and
the memory exchange the data directly, without
processor involvement.
 Interrupt driven I/O, though more efficient
than simple Programmed I/O, still requires the
active intervention of the processor to transfer
data between memory and I/O module, and
any data transfer must travels the path
through the processor.

 When large volumes of data are to be moved,


more efficient technique is required:
Direct Memory Access.
DMA function:
 DMA involves an additional module on system
bus.
 The DMA module is capable of mimicking the
processor and, indeed of taking over control of the
system from the processor.
 It needs to do this to transfer data to and from
memory over the system bus.
 DMA module must use the bus only when
processor does not use it, or it must force the
processor to suspend operation temporarily, and
this technique is referred to as cycle stealing,
because the DMA module in effect steals the bus
cycle.
 When the processor wishes to read and write block
of data, it issues the command to a DMA module,
by sending the following information to the DMA
module:
 Weather the read or write is requested, using the read or
write control line between the processor and DMA
module.
 The address of the I/O device involved, communicated
on the data lines.
 The starting location in memory to read or write to
communicated on the data lines and stored by the DMA
module in its address register.
 The number of words to be read or written, again
communicated via the data lines and store in the data
count register.
 The processor then continues with other work. It has
delegated this I/O operation to the DMA module.
 The DMA module transfers the entire block of data,
one word at a time directly to or from a memory
without going through the processor.
 When the transfer is complete, the DMA module sends
an interrupt signal to the processor. Thus the processor
is involved only at the beginning and end of the
transfer.
 The DMA module acting as a surrogate processor, uses
programmed I/O to exchange data between memory
and I/O module through the DMA module.
e.g. Intel 8237A DMA Controller.
Important functions of OS:
1. Process Management
2. Memory Management
3. IO and File Management
4. CPU Scheduling
5. Hardware Abstraction
6. Networking
7. Protection and Security
8. User Interfacing
UNIX System Architecture:
USER level: User’s program (executable)
KERNEL level:
 System Calls
 File Subsystem
 Process Control Subsystem:
1. IPC
2. CPU Scheduling
3. Memory Management.
 Character Devices & Block Devices: Device Drivers.
 Hardware Control
HARDWARE level:
Hardware(i.e. Real Machine).
Dual Mode Operation:
 In order to ensure the proper execution of the
operating system, we must be able to distinguish
between the execution of operating system code
and user defined code.
 OS operates in two modes:
1. User mode (non-privileged mode) and
2. Kernel mode( also called as supervisor mode,
system mode, or privileged mode).
 A bit, called mode bit, is added to the hardware of
the computer to indicate the current mode:
kernel mode(0)
user mode(1).
System Calls:
 System Calls provides an interface to the services made
available by an OS.
 These calls are generally available as routines written
in C, C++, although certain low-level tasks written
using assembly language instructions.
 Types of system calls:
System calls can grouped roughly into six major
categories.
1. Process control: fork(), exit(), wait()
2. File Manipulation: open(), read(), write(), close()
3. Device Manipulation: ioctl(), read(), write()
4. Information Maintenance: getpid(), alarm(), sleep()
5. Communication: pipe(), shmget(), mmap()
6. Protection: chmod(), umask(), chown().
 The operating system is responsible for the
following activities in connection with process
and thread management.
1. The creation and termination of both user
and system processes.
2. The scheduling of processes.
3. Provision of mechanism for synchronization
4. Inter Process communication
5. Deadlock handling for the processes.
 Program is a passive entity, where as process is
an active entity.
 Process State:
As a process executes, its changes state. The
state of the process is defined in part by the
current activity of that process.
 Each process may be in one of the following
state:
1. New: The process is being created.
2. Running: Instruction are being executed.
3. Waiting: The process is waiting for some
event to occur (such as an IO completion or
reception of an signal).
4. Ready: The process is waiting to be assigned
to a processor.
5. Terminated: The process has finished the
execution.
PCB: Process Control Block
 Each process represented in the OS by a PCB-also
known as task control block.
 It contains many pieces of information associated with
the specific process, including these:
1. Process state
2. Program Counter
3. CPU Registers
4. CPU Scheduling information
5. Memory Management Information
6. Execution Context
7. Accounting Information
8. I/O Status Information
Process Scheduling:
 The objective of multiprogramming is to have
some process running at all times, to maximize
CPU utilization.
 The objective of time sharing is to switch the
CPU among processes so that frequently user
can interact with each program while it is
running.
 Unix is the world’s first multi-programming,
multi-tasking, multi-user operating system.
 Multi-programming:
 In such systems multiple programs can be loaded in
the memory.
 The number of programs can be loaded into the
memory at the same time is called as degree of multi
programming.
 Multi-tasking/time sharing: CPU time is
shared among multiple processes in the main
memory.
 Multi-user:
 Multiple
users can execute multiple tasks
concurrently on the same system

 Multi processor System:


 Thesystems in which multiple processors are
connected in a closed circuit is called as
“multiprocessor computer”.
Scheduling queues:
Job queue: as processes enter the system, they
are put into the Job queue, which consists of all
processes in the system.
Ready queue: the processes that are residing in
main memory and are ready and waiting to
execute are kept on a list called ready queue.
Device queue: The list of processes waiting for
a particular I/O device is called device queue.
Each device has its own device queue.
Scheduler:
1. Long term scheduler or job scheduler:
In the batch system, more processes are submitted
than can be executed immediately.
These processes are spooled to a mass storage
device(typically a disk), where they are kept for
later execution. The long term scheduler or job
scheduler, selects processes from this pool and
loads them into memory for execution.
2. Short term scheduler or CPU scheduler:
The short term scheduler or CPU scheduler selects
from among the processes that are ready to execute
and allocates the CPU to one of them.
Context Switch:
 When an interrupt occurs, the system needs to
save the current context of the process running on
the CPU so that it can restore that context when its
processing is done, essentially suspending the
process and then resuming it.
 The context is represented in the PCB of the
process, it includes the value of the CPU registers,
the process state and memory management
information.
 Generally, we perform state save of the current
state of CPU, be it in kernel or user mode, and then
a state restore to resume operations.
 Switching the CPU to another process requires
performing a state save of current process and
state restore of a different process. This task is
known as Context Switch.
 When the context switch occurs, the kernel
saves the context of old process in its PCB and
loads the saved context of the new process
scheduled to run.
 Process Scheduling or Thread Scheduling:
 CPU Scheduling is the basis of multi programmed
operating systems.
 By switching the CPU among processes, the OS can
make the computer more productive.
 Non-preemptive Scheduling:
Under this type of scheduling, once the CPU
has been allocated to a process, the process
keeps the CPU until it releases the CPU either
by terminating or by switching to waiting
state.
 Dispatcher:
 The dispatcher is the module that gives the control of
CPU to the process selected by the short term scheduler.
 This function involves the following:
 Switching Context
 Switching to user mode
 Jumping to the proper location in the user
program to restart the program.
 Dispatch Latency:
The time it takes for the dispatcher to stop one
process and start another running is known as
dispatch latency.
 Scheduling Criteria:
1. CPU Utilization: MAX :We want to keep CPU as busy
as possible.
2. Throughput: MAX: One measure of work is the
number of processes that are completed per time unit,
is called throughput.
3. Turnaround time: MIN: The interval from the time of
submission of a process to the time of completion is
the turnaround time. So the it is the sum of the periods
spent waiting to get into memory, waiting in the ready
queue, executing on the CPU, and doing I/O.
4. Waiting time: MIN: it is the sum of the periods spent
waiting in the ready queue.
5. Response time: MIN: it is the time from the
submission of a request until the first response is
produced.
 Scheduling Algorithms:
1. FCFS: First-Come, First-Served Scheduling:
 Process arrived first will be scheduled first.
 For implementation FIFO queue can be used.
 FCFS algorithm is non preemptive.
 e.g. Process-CPU Burst Time: P1-24, P2-3, P3-3.
2. SJF: Shortest-Job-First Scheduling:
 Process having minimum burst time will be executed
first
 This algorithm gives minimum waiting time
 e.g. Process-CPU Burst Time: P1-6, P2-8, P3-7, P4-3.
 Preemptive SJF will preempt the currently executing
process. Also refereed as shortest-remaining-time-first
scheduling algorithms.
 e..g Process-Arrival Time-CPU Burst Time
P1-0-8, P2-1-4, P3-2-9, P4-3-5.
3. Priority Scheduling
 e.g. Process-Burst Time-Priority
P1-10-3, P2-1-1, P3-2-4, P4-1-5, P5-5-2.
 Indefinite blocking/starvation.
 Aging
4. Round-Robin Scheduling
 This algorithm gives minimum response time
 e.g. Process-CPU Burst Time.
P1-24, P2-3, P3-3.
time quantum - 4 ms( small CPU time)
5. Multilevel Queue Scheduling:
Depending on the nature of the processes, the
ready queue is splited into the multiple sub-
queues and each queue can have different
scheduling algorithm.
6. Multilevel Feedback Queue Scheduling:
If a process is not getting sufficient CPU time
in its current queue, then it can be shifted into
another queue by OS. This enhanced concept
is known as Multilevel feedback queue.
Multi-Processor Scheduling:
1. Asymmetric Multi-Processing:
 The single processor handles all scheduling decisions,
I/O processing, and other system activities called master
server.
 The other processors execute only user code.
 In this type only one processor accesses the system data
structures, reducing the need for data sharing.
2. Symmetric Multi-Processing:
 Where each processor is self scheduling.
 All processes may be in common ready queue, or each
processor may have its own private queue of ready
processes.
 e.g. Windows XP, Windows 2000, Solaris, Linux and Mac
OS X supports SMP.
INTER PROCESS COMMUNICATION
Independent Process:
 A process is independent if it cannot affect or be
affected by the other process executing in the system.
 Any process that does not share data with any other
process is independent.

Cooperating Process:
 A process is cooperating if it can affect or be affected by
any other process in the system.
 Any process that shares data with any other process is
a cooperating process.
Cooperating processes requires an inter process
communication (IPC) mechanism that will allow
them to exchange data and information.
There are two fundamental models of IPC:
1. Shared Memory Model: In this model, a region
of memory that is shared by cooperating processes
is established. Processes then can exchange
information by reading and writing data to the
shared region.
2. Message Passing Model: In this model,
communication takes place by means of messages
exchanged between the cooperating processes.
 Pipe:
 Pipe is used to communicate between two processes.
 It is a stream based unidirectional communication.
 There are two types of pipe:
 1. Unnamed Pipe: Used to communicate between
related processes.
 2. Named Pipe/FIFO: Used to communicate between
unrelated processes.
 Message Queue:
 Used to transfer packets of data from one process to
other process.
 It is bidirectional IPC mechanism.
 Signals:
 A process can send signal to another process or OS can
send signal to a process. E.g. SIGKILL, SIGSEGV
 Sockets:
 Socket is defined as communication endpoint
 Using socket one process can communicate with another
process on same machine or different machine in the
network.
 Socket = IP Address + Port
 RPC (Remote Procedure Call)
 Used call method from another process on the same
machine or different machine in the network.
Process Coordination/Process Synchronization:
 Cooperating processes can either directly share
a logical address space(i.e. both code and data)
or be allowed share data only through files or
messages.
 Concurrent access to shared data may results in
data inconsistency.
 The mechanisms to ensure the orderly
execution of cooperating processes that share a
logical address space, so that data
inconsistency is maintained.
Critical-Section Problem:
 Consider a system consisting of n processes { P1, P2, …,
Pn-1}. Each process has a segment code, called a critical
section, in which the process may be changing
common variables, updating a table, writing a file and
so on. The important feature of this system is that,
when one process is executing in its critical section, no
other process is to be allowed to execute in its critical
section. That is, no two processes are executing in their
critical sections at the same time.
 The critical section problem is to design a protocol that
processes can use to cooperate. Each process must
request permission to enter its critical section. The
section of code implementing this request is the entry
section. The critical section may be followed by an exit
section. The remaining code is remainder section.
Semaphores:
 To over come the problem of critical section we can
use the synchronization tool called a semaphore.
 Semaphore S is an integer variable that, apart from
initialization is accessed only through two
standard atomic operations: wait( ) and signal( ).
 All modifications to the integer value of the
semaphore in the wait( ) and signal( ) operations
must be executed indivisible. That is when one
process modifies the semaphore value, no other
process can simultaneously modify that same
semaphore value.
Deadlock:
 In multiprogramming environment, several
processes may compete for a finite number of
resources.
 A process requests resources; if the resources
are not available at that time, the process enters
a waiting state.
 Sometimes, a waiting process never again able
to change state, because the resources it has
requested are held by other waiting process.
This situation is called a deadlock.
Necessary Conditions to occur deadlock:
1. Mutual exclusion: resource is not sharable
2. Hold and Wait: process hold a resource and wait for
another resource.
3. No preemption: A resource should not be released until
task is completed.
4. Circular wait
Resource-Allocation Graph:
 Deadlocks can be described more precisely in terms of
directed graphs called as system resource allocation
graph.
 This graph consists of a set of vertices V and set of edges E.
The set of vertices V partitioned into two different types of
nodes: P = { P1, P2, …., Pn }, the set consisting of all the
active processes in the system, and R={R1, R2, …., Rn}, the
set consisting of all resources types in the system.
 The directed edge from process Pi to resource type Rj is
denoted by Pi  Rj; it signifies that Process Pi has requested
an instance of the resource Rj and is currently waiting for
that process.
 A directed edge from resource type Rj to process Pi is
denoted by Rj  Pi; it signifies that Rj has been allocated to
process Pi.
 A directed edge Pi  Rj is called request edge, and a
directed edge Rj  Pi is called assignment edge.
 Pictorially we represents each process Pi as a circle and each
resource as a rectangle. Since resource type Rj may have
more than one instance, we represent each such instance as a
dot within a rectangle.
 If the graph contains no cycle, then no process in the system
is deadlocked. If the graph does contains cycle, then the
deadlock may exists.
Methods of Handling Deadlocks.
1. Deadlock Prevention: For a deadlock to occur,
each of the four necessary conditions must hold.
By ensuring that at least one of these conditions
can not hold, we can prevent the occurrence of
deadlock.
2. Deadlock Avoidance:
1. Resource-Allocation-Graph Algorithm
2. Banker’s Algorithm
3. Recovery from the deadlock:
1. Process termination
2. Resource Preemption
 An address generated by the CPU is commonly
referred to as a logical address, whereas an
address seen by the memory unit - that is, one
loaded into the memory address register of the
memory- is commonly referred to as a
physical address.
 The runtime mapping from virtual/logical to
physical memory addresses is done by a
hardware device called Memory Management
Unit (MMU).
SWAPPING:
 A process must be in memory to be executed. A
process, however, can be swapped temporarily out
of memory to a backing store and then brought
back into memory for continued execution.
 If a higher priority process arrives and wants
service, the memory manager can swap out the
lower priority process and then load and execute
the higher priority process.
 When the high priority process finishes, the lower
priority process can be swapped back in and
continued. This variant of swapping is sometimes
called roll out, roll in.
 Memory Allocation:
1. Contiguous memory allocation, each process is contained in a
single contiguous section of memory.
2. Partition:
 Dynamic Memory Allocation:
1. First Fit: Allocates the first hole that is big enough
2. Best Fit: Allocate the smallest hole that is big enough
3. Worst Fit: Allocate the largest hole
 Generally the first fit is faster than other two algorithms.
 External Fragmentation:
Both the first fit and best fit strategies for memory allocation
suffer from external fragmentation. As processes are loaded and
removed from memory, the free memory space is broken into
little pieces. External fragmentation exists when there is enough
total memory space to satisfy a request but the available spaces
are not contiguous; storage is fragmented into large number of
small holes.
Internal Fragmentation:
Unused memory that is internal to a partition

Solution to the external fragmentation:


1. Compaction: Shuffle the memory contents so as to place all
free memory together in one large block.
2. Noncontiguous memory allocation: Permit the logical
address space of processes to be noncontiguous, thus
allowing a process to be allocated physical memory
wherever such memory available.
 To achieve noncontiguous memory allocation two
techniques are in used:
1. Paging
2. Segmentation
Paging:
 Paging is the memory-management scheme
that permits the physical address space of a
process to be noncontiguous.
 Breaking the physical memory into fixed-size
blocks called frames and breaking logical
memory into blocks of same size called pages.
 Backing store is divided into fixed size blocks
which are of the same size of memory frames.
 The page size like frame size is defined by the
hardware . The size of the page is typically a
power of 2, varying between 512 bytes to 16MB
per page , depending upon the computer
architecture.
Segmentation:
It is a memory-management scheme that supports
this user view of memory. A logical memory is
collection of segments. Each segment has a name
and length. The address specify both the segment
name and the offset within the segment.
 Various memory-management strategies used in
computer systems. All this strategies have the
same goal: to keep many processes in the memory
simultaneously to allow multiprogramming.
 However, they tend to require that an entire
process be in memory before it can execute.
 Virtual memory is a technique that allows the
execution of processes that are not completely in
memory.
 One major advantage of this scheme is that
programs can be larger than physical memory.
 Virtual memory abstracts main memory into an
extremely large, uniform array of storage,
separating logical memory as viewed by the
user from physical memory.
 This technique frees programmers from the
concerns of memory storage limitations.
 Virtual memory also allows processes to share
files easily and to implement shared memory.
 In addition, it also provides an efficient
mechanism for process creation.
Demand Paging:
 A strategy is to load pages only as they are needed
is known as demand paging, and is commonly
used in virtual memory systems.
 With demand-paged virtual memory, pages are
only loaded when they are demanded during
program execution; pages that are never accessed
are thus never loaded into physical memory.
 A demand paging system is similar to paging
system with swapping where processes reside in
secondary memory(usually disk).
 When we want to execute a process, we swap it into the
memory. Rather than swapping the entire process into
memory, however we use lazy swapper.
 A lazy swapper never swaps the page into memory unless
that page will be needed.
 Page replacement: is a basic to demand paging. It completes
the separation between logical memory and physical
memory.
Hardware to support demand paging:
1. Page table: This table has the ability to mark an entry
invalid through a valid-invalid bit or special value of
protection bits.
2. Secondary memory: It is known as swap device, and the
section of the disk used for this purpose is known as swap
space.
Page Replacement Algorithms:
1. FIFO (First In First Out)

2. Optimal Page Replacement: which has the


lowest page fault rate. Replace the page that
will not be used for the longest period of time.
3. LRU Page Replacement: If we use recent past
as an approximation of the near future, then
we can replace the page that has not been used
for longest period of time.
4. Counting Based Page Replacement:

Least Frequently Used(LFU)


Most Frequently Used(MFU)
 Thrashing:
 The high paging activity is called thrashing.
 A process is thrashing if it is spending more
time on paging than executing.
 Since main memory is too small to
accommodate all the data and programs
permanently, the computer system must
provide secondary storage to backup main
memory.
 Modern Computer systems uses disk as the
primary online storage medium for
information.
 The File system provides the mechanism for
on-line storage of and access to both data and
programs residing on the disks.
The device that attach to a computer vary in
many aspects.
 Some devices transfers a character or a block
of characters at a time.
 Some can be accessed only sequentially, others
randomly.
 Some transfers data synchronously and some
asynchronously.
 Some are dedicated, some shared.
 They can be read-only or read-write.
 They vary greatly in speed.
 In many ways, they are also the slowest major
component of the computer.
 Because of all this device variation, the OS
needs to provide a wide range of functionality
to applications, to allow them to control all
aspects of the device.
 The OS abstracts from the physical properties
of the storage devices to define a logical storage
unit, the file.
 File is a named collection of related information
that is recorded on secondary storage.
 In general: file is a sequence/stream of bits, bytes,
lines or records.
 Any file has:
 Data(contents of the file)
 Metadata(information about the file)
 Size of the file
 User/group information
 Time stamps: creation, accessed, modified
 Type of file
 Information about data blocks of that file
 File Type:
Executable(.exe, .com, .bin) , Object(.o, .obj),
Source code (.c, .cpp, .java, .asm), Batch (.bat,
sh ), Text (.txt, .doc), Word Processor (wp, .doc,
.tex), Multi media(mpeg, mov, rm, mp3, avi)
 FILE SYSTEM:
 FileSystem is way of organizing the contents on the
disk.
 During formatting file system is created
Logical File System:
 Logical File system manages metadata information.
 Metadata includes all the file- system structure
except the actual data(or contents of the file).
 It maintains the file structure via file control blocks.
A file control block(FCB) (in UNIX: inode) contains
the information about the file, including ownership,
permissions, and location of the file contents.
 The logical file system is also responsible for
protection and security.
Any File System is logically divided into four parts:

1. Boot Block/Boot Sector:


 It contains the bootstrap program and boot loader
program.

2. Super Block/Volume Control Block:


 It contains info about: the partition, partition size,
label, no. of data blocks, no. of free data blocks
and info about free data blocks. Information about
other blocks.
3. i-node List/Mater File Table:
 The information/metadata of a file is stored in
a structure is called as “file control block” or
“inode”
 Collection of inodes in a partition is called as
“i-node list”.
4. Data Block:
The data or the contents of file are stored in
data block.
 FAT: File Allocation Table: e.g. Win 95
 Disk Allocation Mechanisms:
Each file system allocates data blocks to the file
in different ways:
1. Contiguous Allocation:
 No. of blocks required for the file are allocated
contiguously.
 inode of the file contains starting block address and
number of data blocks.
 Faster sequential random access
2. Linked Allocation:
 Each data block of the file contains data/contents
and address of next data block of that file.
 Inode contains address of starting and ending data
block.
 No external fragmentation, faster sequential access
 Slower random access
 E.g. FAT
3. Indexed Allocation:
 A special data block contains addresses of data block
of the file. This block is called as “index block”
 The address of the index block is stored in the inode
of the file
 No external fragmentation, faster random and
sequential access.
 File can not grow beyond certain limit
Disk Scheduling:
HDD Structure:
 Access Time: Time required to perform read/write
operation on a particular sector of the disk, is called
as “disk access time”.
 Disk access time includes two components = seek
time + rotational latency
 Seek Time: is the time required to move head to
desired cylinder(track)
 Rotational Latency: is the time required to rotate the
platters so that desired sector is reached to the head.
Disk Scheduling Algorithms:
When number of requests are pending for
accessing disk cylinders, magnetic head is moved
using certain algorithms, they are called as disk
scheduling algorithms.
1. FCFS:
requests are handled in the order in which they
arrives
2. SSTF (Shortest Seek Time First ):
requests of nearest(to current position of magnetic
head) cylinder is handled first
3. SCAN or Elevator:
Magnetic head keep moving from 0 to max
cylinder and in reverse order continuously
serving cylinder requests.
4. C-SCAN:
Magnetic head keep moving from 0 to max
cylinder serving the requests and then jump
back to 0 directly.

5. LOOK:
 Implementation policy of SCAN or C-SCAN
 If no requests pending magnetic head is stopped.

You might also like