SlideShare a Scribd company logo
20IT401-OPERATING SYSTEMS
UNIT-I
INTRODUCTION AND OPERATING
SYSTEM STRUCTURES
By
Dr. G. Sumathi
ASP/AI & DS
Kongunadu College of Engineering and Technology
What is Operating System?
• Operating system is a program that controls
the execution of application programs.
• Interface between user and computer
hardware.
 Software types :
- Application s/w
- System s/w
System s/w types:
-To create program development
environment ( TE, Compiler,Assembler,
Debugger)
-To create run time environment
(Loader, Libraries, OS)
MAINFRAME SYSTEMS
 First computer used to handle many
commercial scientific applications.
 Large organizations for critical
applications like bulk data processing for
tasks.
A. Batch /Early System
 Early computers were physically large
machine.
 In these systems the user did not interact
directly with the computer system.
B. Multi-programmed System
 Multi-programming concept increases CPU
utilization by organization jobs.
 The operating system keeps several jobs in
memory.
C.Time Sharing System
 The time sharing system is also known as
multi user systems.
 The CPU executes multiple jobs by
switching among them but the switches
occurs so frequently that the user can
interact with each program while it is
running.
PERSONAL COMPUTER SYSTEM / DESKTOP
SYSTEM
 Personal computer appeared in 1970‘s.
They are microcomputers that are smaller
& less expensive than mainframe systems.
 At first file protection was not necessary
on a personal machine. But when other
computers 2nd other users can access the
files on a pc file protection becomes
necessary.
 E.g : windows 98, windows 2000, Linux.
MULTIPROCESSOR SYSTEMS
 Multiprocessor operating system allows the
multiple processors.
 Main objective of using multiprocessor
operating system is to consume high
computing power and increase the
execution speed of system.
DISTRIBUTED SYSTEMS
 A distributed system is a system whose
components are located on different
networked computers, which
communicate and coordinate their
actions by passing messages to one
another.
 processors do not share memory or a
clock.
 processor has its own local memory.
Types:
1. Client/Server Systems:-client requests a resource
and the server provides that resource
2. Peer to Peer Systems:-equal participants in data
sharing
Advantages of Distributed Systems
 Resource sharing
 Computation speed up
 Reliability
 Effective communication
 Nodes can easily share data with other nodes.
 More nodes can easily be added
 Failure of one node does not lead to the failure of the entire
distributed system.
 Disadvantages of Distributed Systems
 It is difficult to provide adequate security in
distributed systems
 Some messages and data can be lost in the
network while moving from one node to
another.
 The database connected to the distributed
systems is quite complicated
 Overloading may occur in the network if all
the nodes of the distributed system try to
send data at once.
CLUSTERED SYSTEMS
 Clustered Operating Systems work
similarly to Parallel Operating Systems as
they have many CPUs.
 Clustered systems are made by two or
more individual systems but they are
connected with each other.
 Independent computer system along with
shared storage medium and all systems
perform all tasks together
Types of Clustered System
1. Asymmetric Clustering System: -one node in the cluster
system is getting as hot standby mode (monitors all functions )
2. Symmetric Clustering System: -multiple nodes help to run all
applications, and it monitors all nodes at same time.
3. Parallel Cluster System: - allows to multiple users to access
similar data on the common shared storage system
Advantages of Clustered System:
 Clustered system provides much better performance
 Clustered system is better fault tolerance system, if anyone node gets fail
then entire system does not halt.
 Clustered system has great scalability because we can easily add new
node with this system.
Disadvantages of Clustered System
 It is more costly because it contains expensive hardware and its design.
 Required multiple servers and other hardware components for making
one
 It is very hard to monitor and maintenance this system.
REALTIME SYSTEMS
 Multiple programs are being executed at the
same time on a single processing core.
 System that controls scientific experiments,
medical imaging systems and some display
systems are real time systems.
Types:
1. Hard real time systems:- critical task has been completed
on time
2. Soft real time systems: - critical task gets priority over
other tasks
HANDHELD SYSTEMS
 Handheld systems include Personal
Digital Assistants (PDAs), such as Cellular
Telephones with connectivity to a
network such as the Internet.
 Handheld devices may use wireless
technology such as BlueTooth, allowing
remote access to e-mail and web
browsing.
HARDWARE PROTECTION
 If a computer system has multiple users and
allows the concurrent execution of multiple
processes, then access to data must be
regulated.
 Mechanisms ensure that files, memory
segments, CPU, and other resources can be
operated on by only those processes that have
gained proper authorization from the operating
system.
 For example, memory-addressing hardware
ensures that a process can execute only within
its own address space.
Basic Elements
 Processor - Controls the operation of the computer
and performs its data processing functions.
 Main memory - Stores data and programs.
 I/O Module - Move data between the computer
and its external environment.
 System bus - Provides for communication among
processors, main memory and I/O modules.
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
Instruction Execution
 A program consists of a set of instructions
stored in memory .
 Instruction execution takes place in CPU
registers
• processor reads (fetches)
instructions from memory
• processor executes each instruction
Two steps:
Basic Instruction Cycle
Instruction Fetch
and Execute
 The processor fetches the instruction from
memory
 Program counter (PC) holds address of the
instruction to be fetched next
PC is incremented after each fetch
INSTRUCTION EXECUTION FULL
CYCLE
Interrupts
• It is an event external to the currently executing
process that cause a change in the normal flow of
instruction execution.
• They tell the CPU to stop its current activities and
execute the appropriate part of the OS
 Interrupt the normal sequencing of the processor
 Provided to improve processor utilization
Storage structure
Cache Memory
 The cache memory is small, fast memory
between the processor and main memory.
 Cache memory is smaller, faster memory and
it contains a portion of main memory.
CACHE
AND
MAIN
MEMORY
Direct Memory Access
 Transfers the entire block of data directly
to and from memory without going
through the processor
 processor is involved only at the beginning and end
of the transfer
 processor executes more slowly during a transfer
when processor access to the bus is required
 More efficient than interrupt-driven or
programmed I/O
OS services
1.Program development – provides facilities such as
editors in creating programs
2.Program execution – loading program into
memory, I/O devices and files initialization
3.Access to I/O devices – using reads and writes
4.Controlled access to files – protection
mechanisms in accessing in multiuser system
5.System access – provide protection of resources
OS services
6.Error detection and response – Hardware errors
- such as a memory error, or a device failure or
malfunction;
Software errors - division by zero, attempt to
access forbidden memory location.
OS provides a response that clears the error
condition
7.Accounting:
A good OS will collect usage statistics for various
resources and monitor performance parameters
such as response time.
->To improve performance in future
-> Billing in multiuser system
OS Services:
System Calls
 System calls provide an interface between running
program and an operating system.
 Typically written in a high-level language (C or C++)
 A system call is an explicit request to kernel mode
via software interrupt.
 It is like procedure call but system call enters
kernel.
 All system call return an integer value.
 In the kernel positive or 0 denote successful
termination and negative value denotes error
condition.
 Three general methods are used to pass
parameters to the operating system.
1. The simplest approach is to pass the
parameters in registers.This is the approach
taken by Linux and Solaris.
2. Parameters also can be placed, or pushed,
onto the stack by the program and popped
off the stack by the operating system.
3. The parameters are generally stored in a
block, or table in memory, and the address of
the block is passed as a parameter in a
register
API – System Call – OS Relationship
Examples of Windows and Unix System Calls
System Programs
 Modern OS is a collection of system programs.
 Provide application programming environment on
hardware for program development and execution
◦ Some of them are simply user interfaces to
system calls; others are considerably more
complex
Categories of system calls:
 File management - Create, delete, copy, rename,
print, dump, list, and generally manipulate files and
directories
 Status information
◦ Some ask the system for info - date, time,
amount of available memory, disk space,
number of users
◦ Others provide detailed performance, logging,
and debugging information
◦ Typically, these programs format and print the
output to the terminal or other output
devices
◦ Some systems implement a registry - used
to store and retrieve configuration
information
Operating System Structure
 General-purpose OS is very large
program
 Various structure
◦ Simple structure – MS-DOS
◦ More complex -- UNIX
◦ Layered – an abstraction
◦ Microkernel -Mach
Simple Structure -- MS-DOS
 Small and simple in
size
 In new versions –
size increased
 Application
programs directly
interact with BIOS
driver(DA)
Non Simple Structure -- UNIX
UNIX – limited by hardware functionality,
The UNIX OS consists of two parts
◦ Systems programs
◦ The kernel
- Provides system calls for the file system,
CPU scheduling, memory management
Traditional UNIX System Structure
Layered Approach
 The operating system is divided
into a number of layers (levels),
 The bottom layer (layer 0), is the
hardware;
 the highest (layer N) is the user
interface.
 Functionality of each layer is
fixed.
 Each layer consist of data
structure and set of routines
 With modularity, layers are
selected such that each uses
functions (operations) and
services of only lower-level layers
 Each layer is using system calls
for performing their function
Kernel
 Kernel is a software code that resides in the central core of a
operating system.
 Shell is outer part of OS and it interacts with user commands.
 Kernel does not directly interact with user. It interacts with
shell.
 Kernel is the first part of OS loaded into memory and remains
entire computer session.
 Kernel code is in protected area in memory.
 Kernel works in kernel space.
 User performs in user space.
 Memory – two areas
1. System area 2. User area
VIRTUAL MACHINES:
 Virtualization technology enables a single PC or
server to simultaneously run multiple operating
systems or multiple sessions of a single OS
 The host operating system can support a number of
virtual machines (VM),
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
SYSTEM DESIGN AND
IMPLEMENTATION:
Design Goals:
 The first problem in designing a system is to
define goals and specifications.
 At the highest level, the design of the system
will be affected by the choice of hardware and
the type of system.
 User goals - system should be convenient to
use, easy to learn and to use, reliable, safe, and
fast
 System goals.- system should be easy to design,
implement, and maintain.
Implementation:
 Once an operating system is designed, it must
be implemented.
 Because operating systems are collections of
many programs, written by many people over
a long period of time, it is difficult to make
general statements about how they are
implemented.
 Early operating systems were written in
assembly language.
 Now, although some operating systems are
still written in assembly language, most are
written in a higher-level language (C, C++, etc).
UNIT 2 PROCESS MANAGEMENT
Objectives:
 To introduce the notion of a process -- a program in
execution, which forms the basis of all computation
 To describe the various features of processes, including
scheduling, creation and termination, and communication
 To explore interprocess communication using shared
memory and message passing
 To describe communication in client-server systems
Process Concept
 Process – a program in execution.
 A process is the unit of work in a modern time-sharing system.
 Multiple parts
◦ The program code, also called text section
◦ Stack containing temporary data
 Function parameters, return addresses, local variables
◦ Data section containing global variables
◦ Heap containing memory dynamically allocated during run time
Process State
 As a process executes, it changes state
◦ new: The process is being created
◦ running: Instructions are being executed
◦ waiting: The process is waiting for some event to occur
◦ ready: The process is waiting to be assigned to a processor
◦ terminated: The process has finished execution
Diagram of Process State
Operating System
Concepts
Process Scheduling:
 Job queue – set of all processes in the system.
 Ready queue – set of all processes residing in main memory, ready
and waiting to execute.
 Device queues – set of processes waiting for an I/O device.Each
device has own queue
 Process is moved between the various queues.
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
Schedulers
 Long-term scheduler (or job scheduler):
- selects which processes should be brought into
the ready queue.
 Medium term scheduler
- Part of swapping function.
- Removes process from memory for I/O
- May lead to suspended state (disk).
OPERATIONS ON PROCESSES
Process Creation:
 OS creates new process with specified
attributes and identifiers.
 The creating process is called a parent
process, where as the new processes are
called the children of that process
 Parent process creates children processes, which, in
turn create other processes, forming a tree of
processes.
 Resource sharing
◦ Parent and children share all resources.
◦ Children share subset of parent’s resources.
 Execution
◦ Parent and children execute concurrently.
◦ Parent waits until children terminate.
Process Creation (Cont.)
 UNIX examples
◦ fork system call creates new process
Void main()
{
fork();
}
◦ execve system call used after a fork to
replace the process’ memory space with a
new program.
Process Termination
 Process executes last statement and asks the operating system
to decide it (exit).
 Parent may terminate execution of children processes
(abort).
1.Normal completion of operation
2.Memory is not available
3.Time slice expired
4.Parent termination
5.Failure of I/O
6.Request from parent process
7.Misuse of access rights
COOPERATING PROCESSES
 A process is independent if it cannot
affect or be affected by the other
processes executing in the system.
 A process is cooperating if it can affect or
be affected by the other processes
executing in the system.
Reason for cooperating processes
 Information sharing
 Computation speedup (By exec sub
tasks parallel)
 Modularity(dividing the system functions
into separate processes or threads)
 Convenience
Producer – Consumer Problem:
 A producer process produces information
that is consumed by a consumer process.
 For example, a print program produces
characters that are consumed by the printer
driver.A compiler may produce assembly
code, which is consumed by an assembler.
 To allow producer and consumer processes to
run concurrently, we must have available a
buffer of items that can be filled by the
producer and emptied by the consumer.
 unbounded-buffer: places no practical limit on
the size of the buffer.
 bounded-buffer : assumes that there is a fixed
buffer size.
Interprocess Communication (IPC)
 Operating systems provide the means for
cooperating processes to communicate with
each other via an inter process communication
(PC) facility.
 IPC provides a mechanism to allow processes
to communicate and to synchronize their
actions.
 IPC is best provided by a message passing
system.
COPY
 Inter process communication is achieved
through,
1. Shared Memory - memory shared among
the processes
2. Message Passing – communicate and to
synchronize their actions
IPC facility provides two operations:
 send(message)
 receive(message)
(a) Message passing. (b) shared memory
THREADS – OVERVIEW
 A thread is the basic unit of CPU utilization.
 It is sometimes called as a lightweight process.
 It consists of a thread ID, a program counter, a register set
and a stack.
User thread and Kernel threads
User threads:
-It uses user space for thread scheduling
-Transparent to OS
- Created by run time libraries and cannot
execute privileged instructions
- smaller and faster
EX:POSIX pthreads, Mach C-threads
 Kernel thread
-Thread management is done by kernel.
-OS supports KLT.
-Threads are constructed and controlled
by system calls.
Ex:Windows 95/98/NT
Multithreading models
 In many applications,user level threads are
mapped with kernel level threads.
1.One to one
2.Many to one
3.Many to many
One to One
 One user level thread is mapped with one
kernel level thread.
 For 3 UT,Kernel creates 3 KT
 Ex:Windows 95/XP,LINUX
Many to one
 Many user level threads are mapped with
one kernel level thread.
 Single thread of control
Ex: Green threads for SOLARIS
Many to many
 Many user level threads map with many kernel
level threads
 M-to-N thread mapping
CPU SCHEDULING
 Selects one process among the processes in
memory that are ready to execute, and
allocates the CPU to one of them.
 CPU scheduling is the basis of multi-
programmed operating systems.
CPU-I/O Burst Cycle:
 Process execution consists of a cycle of CPU
execution and I/O wait.
 Process execution begins with a CPU burst.
CPU Scheduler:
 Whenever the CPU becomes idle, the
operating system must select one of the
processes in the ready queue to be executed.
 The selection process is carried out by the
short-term scheduler (or CPU scheduler).
 The ready queue is not necessarily a first-in,
first-out (FIFO) queue. It may be a FIFO
queue, a priority queue, a tree, or simply an
unordered linked list.
Preemptive Scheduling:
A scheduling method that interrupts the processing of a process
and transfers the CPU to another process.
CPU scheduling decisions may take place under the following four
circumstances:
1. When a process switches from the running state to the waiting
state.
2. When a process switches from the running state to the ready
state.
3. When a process switches from the waiting state to the ready
state.
4. When a process terminates.
 Under 1 & 4 scheduling scheme is non preemptive.
 Otherwise the scheduling scheme is preemptive.
Non-Preemptive Scheduling:
 In non preemptive scheduling, once the
CPU has been allocated a process, the
process keeps the CPU until it releases
the CPU either by termination or by
switching to the waiting state.
Dispatcher:
 The dispatcher is the module that gives control
of the CPU to the process selected by the short-
term scheduler.
This function involves:
1. Switching context
2. Switching to user mode
3. Jumping to the proper location in the user
program to restart that program.
SCHEDULING CRITERIA
1. CPU utilization: The CPU should be kept as
busy as possible. CPU utilization may range from 0
to 100 percent.
2. Throughput: It is the number of processes
completed per time unit.
3. Turnaround time: The interval from the time of
submission of a process to the time of completion
is the turnaround time.
Turnaround time 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: Waiting time is the sum
of the periods spent waiting in the ready
queue.
5. Response time: It is the amount of
time it takes to start responding, but not
the time that it takes to output that
response.
First Come First Serve CPU Process Scheduling in Operating
Systems
Example
1. S. No Process ID Process Name Arrival Time Bu
rst Time
2. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
3. 1 P 1 A
0 9
4. 2 P 2 B
1 3
5. 3 P 3 C
1 2
6. 4 P 4 D
1 4
7. 5 P 5 E
2 3
8. 6 P 6 F
 Non Pre Emptive Approach
Gantt chart for the above Example 1 is:
 Turn Around Time = Completion Time
- Arrival Time
 Waiting Time = Turn Around Time -
Burst Time
Solution to the Above Question Example 1
S. No Process ID Arriva
l Time
Burst
Time
Completion
Time
Turn
Around
Time
Waiting
Time
1 P 1 A 0 9 9 9 0
2 P 2 B 1 3 12 11 8
3 P 3 C 1 2 14 13 11
4 P 4 D 1 4 18 17 13
5 P 5 E 2 3 21 19 16
6 P 6 F 3 2 23 20 18
 The Average Completion Time is:
 Average CT = ( 9 + 12 + 14 + 18 + 21 + 23 ) / 6
 Average CT = 97 / 6
 Average CT = 16.16667
 The Average Waiting Time is:
 Average WT = ( 0 + 8 + 11 + 13 + 16 + 18 ) /6
 Average WT = 66 / 6
 Average WT = 11
 The Average Turn Around Time is:
 Average TAT = ( 9 + 11 + 13 + 17 + 19 +20 ) / 6
 Average TAT = 89 / 6
 Average TAT = 14.83334
 This is how the FCFS is solved in Non Pre Emptive Approach.
Pre Emptive Approach
 Gantt chart for the above Example 1 is:
S. No Process ID Arrival
Time
Burst
Time
Compl
etion
Time
Turn
Around
Time
Waiting
Time
1 P 1 A 0 9 23 23 14
2 P 2 B 1 3 8 7 4
3 P 3 C 1 2 3 2 0
4 P 4 D 1 4 15 14 10
5 P 5 E 2 3 11 9 7
6 P 6 F 3 2 5 2 0
 The Average Completion Time is:
 Average CT = ( 23 + 8 + 3 + 15 + 11 + 5 ) / 6
 Average CT = 65 / 6
 Average CT = 10.83333
 The Average Waiting Time is:
 Average WT = ( 14 + 4 + 0 + 10 + 7 + 0 ) /6
 Average WT = 35 / 6
 Average WT = 5.83333
 The Average Turn Around Time is:
 Average TAT = ( 23 + 7 + 2 + 14 + 9 +2 ) / 6
 Average TAT = 57 / 6
 Average TAT = 9.5
 This is how the FCFS is solved in Pre Emptive Approach.
Shortest Job First CPU Scheduling Algorithm
Examples for Shortest Job
First
ProcessID Arrival Time Burst Time
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
P0 1 3
P1 2 6
P2 1 2
P3 3 7
P4 2 4
P5 5 5
Non Pre Emptive Shortest Job First CPU Scheduling
Process ID Arrival
Time
Burst Time Completio
n Time
Turn
Around
Time TAT
= CT - AT
Waiting
Time WT =
TAT - BT
P0 1 3 5 4 1
P1 2 6 20 18 12
P2 0 2 2 2 0
P3 3 7 27 24 17
P4 2 4 9 7 4
P5 5 5 14 10 5
Gantt Chart
Average Completion Time:
1. Average Completion Time = ( 5 + 20 + 2 + 27 + 9 + 14 ) / 6
2. Average Completion Time = 77/6
3. Average Completion Time = 12.833
Average Waiting Time:
4. Average Waiting Time = ( 1 + 12 + 17 + 0 + 5 + 4 ) / 6
5. Average Waiting Time = 37 / 6
6. Average Waiting Time = 6.666
Average Turn Around Time:
7. Average Turn Around Time = ( 4 +18 + 2 +24 + 7 + 10 ) / 6
8. Average Turn Around Time = 65 / 6
9. Average Turn Around Time = 6.166
Pre Emptive Approach
Process ID Arrival
Time
Burst Time Completio
n Time
Turn
Around
Time TAT
= CT - AT
Waiting
Time WT
=TAT - BT
P0 1 3 5 4 1
P1 2 6 17 15 9
P2 0 2 2 2 0
P3 3 7 24 21 14
P4 2 4 11 9 5
P5 6 2 8 2 0
Gantt Chart
Average Completion Time
1. Average Completion Time = ( 5 + 17 + 2 + 24 + 11 +8 ) /
6
2. Average Completion Time = 67 / 6
3. Average Completion = 11.166
Average Turn Around Time
4. Average Turn Around Time = ( 4 +15 + 2 + 21 + 9 + 2 ) /
6
5. Average Turn Around Time = 53 / 6
6. Average Turn Around Time = 8.833
Average Waiting Time
7. Average Waiting Time = ( 1 + 9 + 0 + 14 + 5 + 0 ) /6
8. Average Waiting Time = 29 / 6
9. Average Waiting Time = 4.833
Non Preemptive Priority Scheduling
Process ID Priority Arrival Time Burst Time
1 2 0 3
2 6 2 5
3 3 1 4
4 5 4 2
5 7 6 9
6 4 5 4
7 10 7 10
Gantt Chart
Proces
s Id
Priorit
y
Arriva
l Time
Burst
Time
Compl
etion
Time
Turnar
ound
Time
Waitin
g
Time
Respo
nse
Time
1 2 0 3 3 3 0 0
2 6 2 5 18 16 11 13
3 3 1 4 7 6 2 3
4 5 4 2 13 9 7 11
5 7 6 9 27 21 12 18
6 4 5 4 11 6 2 7
7 10 7 10 37 30 18 27
1.Turn Around Time = Completion Ti
me - Arrival Time
2.Waiting Time = Turn Around Time -
Burst Time
3.AverageWaiting Time =
(0+11+2+7+12+2+18)/7=52/7
Avg Waiting Time = (0+11+2+7+12+2+18)/7 = 52/7 units
Preemptive Priority Scheduling
Process Id Priority Arrival Time Burst Time
1 2(L) 0 1
2 6 1 7
3 3 2 3
4 5 3 6
5 4 4 5
6 10(H) 5 15
7 9 15 8
Gantt Chart
1.Turnaround Time = Completion Tim
e - Arrival Time
2.Waiting Time = Turn Around Time -
Burst Time
 Avg Waiting Time =
(0+14+0+7+1+25+16)/7 = 63/7 = 9
units
Process
Id
Priority Arrival
Time
Burst
Time
Comple
tion
Time
Turn
around
Time
Waiting
Time
1 2 0 1 1 1 0
2 6 1 7 22 21 14
3 3 2 3 5 3 0
4 5 3 6 16 13 7
5 4 4 5 10 6 1
6 10 5 15 45 40 25
7 9 6 8 30 24 16
RR Scheduling Example
Assume Time Quantum TQ = 5
S. No Process ID Arrival Time Burst Tim
e
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
1 P 1 0 7
2 P 2 1 4
3 P 3 2 15
4 P 4 3 11
5 P 5 4 20
6 P 6 4 9
Ready Queue
P1, P2, P3, P4, P5, P6, P1, P3, P4, P5, P6, P3, P4, P5
Gantt Chart
 Average Completion Time
1. Average Completion Time = ( 31 +9 + 55 +56 +66 + 50 ) / 6
2. Average Completion Time = 267 / 6
3. Average Completion Time = 44.5
 Average Waiting Time
1. Average Waiting Time = ( 5 + 26 + 5 + 42 + 42 + 37 ) / 6
2. Average Waiting Time = 157 / 6
3. Average Waiting Time = 26.16667
 Average Turn Around Time
1. Average Turn Around Time = ( 31 + 8 + 53 + 53 + 62 + 46 ) / 6
2. Average Turn Around Time = 253 / 6
3. Average Turn Around Time = 42.16667
CASE STUDY: LINUX SCHEDULING
 the Completely Fair Scheduler (CFS)
became the default Linux scheduling
algorithm.
 Scheduling in the Linux system is based on
scheduling classes.
 Each class is assigned a specific priority.
 Equally divides the CPU time among all the
processes
Unit – 3
PROCESS SYNCHRONIZATION AND
DEADLOCKS
ProcessesTypes
The two types of processes are
 Cooperating Processes
 Can affect or be affected by the execution of another
process
 A process that shares data with other processes or share a
logical address space.
 Independent Processes
 Cannot affect or be affected by the execution of another
process
 A process that does not share data.
INTRODUCTION :
 The best example to see the cooperation
between two processes is Producer
Consumer problem.
 It is also known as the bounded-buffer
problem.
 The problem contains two processes:
 the producer and the consumer.
 Both processes share a common, fixed-size
buffer used as a queue.
 Producer produces and consumer consumes.
Example:
Producer-Consumer Problem:
 Types
Unbounded-buffer:
◦ No practical limit on the size of the buffer
◦ Consumer may wait, producer never waits
Bounded-buffer:
◦ Assumes that there is a fixed buffer size
◦ Consumer waits for new item, producer waits if buffer is full.
Race Conditions:
The situation where several processes access and
manipulate shared data concurrently and the out
come of execution depends on the particular order in
which the access takes place are called race conditions
Critical Section (CS)
 Each process has a code segment, called critical
section, in which the shared data is accessed.
 When one process is executing in the critical
section, no other process is to be allowed in its
critical section.This is the problem of Critical
Section Problem.
CRITICAL SECTION PROBLEM:
Types of Section:
 Each process must request permission to enter its
critical section.
1. Entry Section(ES)
 Section of code implementing the request
permission to enter the critical section.
2. Exit Section (LS)
 Section of code to leave the critical section which
follows Entry Section.
3. Remainder Section(RS)
 Remaining code of the process after the critical
section.
Structure of process Pi
do {
entrysection
Criticalsection
exit section
Remaindersection
} while(1);
1.Mutual Exclusion
 If process Pi is executing in its critical
section, then no other processes can be
executing in their critical sections
2. Progress
 If no process is executing in its critical section and
there exist some processes that wish to enter their
critical section, then the selection of the processes
that will enter the critical section next cannot be
postponed indefinitely
◦ If only one process wants to enter, it should be able to
◦ If two or more want to enter, one of them should succeed
Solution to Critical Section Problem:
3. Bounded Waiting :
 A bound must exist on the number of
times that other processes are allowed to
enter their critical sections after a process
has made a request to enter its critical
section and before that request is granted.
 Mutex is short for Mutual exclusion
 Mutex lock is used to solve the critical-
section problem
Used to ensure exclusive access to data
shared between threads
Used to protect critical regions and thus
prevent race conditions
MUTEX LOCKS:
 Illustration
 A process must acquire the lock before entering
a critical section using acquire () function releases
the lock when it exits the critical section using
release() function
SEMOPHORES:
 Semaphore is a synchronization tool (provided
by the OS) that does not require busy waiting .
 Semaphore is a variable that has an integer
value
 May be initialized to a non negative number
 Wait operation decrements the semaphore value
 Signal operation increments semaphore value
SYNCHRONIZATION HARDWARE:
 A semaphore S is an integer variable that ,apart
from initialization ,can only be accessed through
2 atomic and mutually exclusive operations:
 wait(S)-Originally called P(), from Dutch proberen to test.
―
 signal(S) -Originally calledV(), from Dutch verhogen to
―
increment.
 Wait and Signal Operations
 Busy-waiting implementation of these in divisible (atomic)
operations:
wait(S)
{
while(S <=0 )
;
S--;
}
signal(S)
{
S++;
}
Usage of Semaphore:
 Two or more processes can cooperate by means of simple
signals such that a process can be forced to stop at a
specified place until it has received a specified signal.
Usage1:Critical Section of n Processes Problem
Shared data
Semaphore mutex;
Structure of Process Pi
do {
wait(mutex);
critical section
signal(mutex);
Remainder section
}while(1);
 Usage2: synchronization of 2 processes
inserting the following statements inP1
s1;signal(mutex);
and the following statements in P2
wait(mutex)s2;
 Deadlock is a situation that occurs when two
processes are waiting for the other to
complete before proceeding
 Types of Deadlock
 Process Deadlock
 A process is deadlocked when it is waiting on an event which
will never happen
 System Deadlock
 A system is deadlocked when one or more processes are
deadlocked
DEADLOCK
System Model
 System consists of resources
 Resource types :
1.Reusable - Processor, memory space, I/O devices
2.Consumable – interrupts,messages
 Each resource type Ri has Wi instances.
 Each process utilizes a resource in sequence:
◦ request
◦ use
◦ release
Deadlock Characterization
 Mutual exclusion: only one process at a time can use
a resource
 Hold and wait: a process holding at least one
resource is waiting to acquire additional resources held
by other processes
 No preemption: a resource can be released only
voluntarily by the process holding it, after that process
has completed its task
Deadlock can arise if four conditions hold simultaneously.
 Circular wait: there exists a set {P0, P1, …, Pn}
of waiting processes such that P0 is waiting for a
resource that is held by P1, P1 is waiting for a
resource that is held by P2, …, Pn–1 is waiting for a
resource that is held by Pn, and Pn is waiting for a
resource that is held by P0.
Resource-Allocation Graph
 V is partitioned into two types:
◦ P = {P1, P2, …, Pn}, the set consisting of all the processes in
the system
◦ R = {R1, R2, …, Rm}, the set consisting of all resource types
in the system
 request edge – directed edge Pi  Rj
 assignment edge – directed edge Rj  Pi
A set of vertices V and a set of edges E.
Resource-Allocation Graph (Cont.)
 Process
 Resource Type with 4 instances
 Request edge : Pi requests instance of Rj
 Claim edge : Pi is holding an instance of Rj
Pi
Pi
Rj
Rj
Example of a Resource Allocation Graph
Resource Allocation Graph With A Deadlock
Graph With A Cycle But No Deadlock
Deadlock solution
◦ Deadlock prevention-remove possibility of deadlock
occurring
◦ Deadlock avoidance – Identifying safe and unsafe states
◦ Deadlock detection
◦ Deadlock recovery
Deadlock Prevention
 Mutual Exclusion – not required for sharable resources
(e.g., read-only files); must hold for non-sharable
resources
 Hold and Wait – must guarantee that whenever a
process requests a resource, it does not hold any other
resources
Restrain the ways request can be made
Deadlock Prevention (Cont.)
 No Preemption –
◦ If a process that is holding some resources requests
another resource that cannot be immediately allocated
to it, then all resources currently being held are released
 Circular Wait – impose a total ordering of all resource
types, and require that each process requests resources in
an increasing order of enumeration
Deadlock Avoidance
 Resource-allocation state is defined by the
number of available and allocated resources, and
the maximum demands of the processes
Safe State
 When a process requests an available resource, system must
decide if immediate allocation leaves the system in a safe state
 System is in safe state if there exists a sequence <P1, P2, …, Pn>
of ALL the processes in the systems such that for each Pi, the
resources that Pi can still request can be satisfied by currently
available resources + resources held by all the Pj, with j < I
Basic Facts
 If a system is in safe state  no
deadlocks
 If a system is in unsafe state 
possibility of deadlock
 Avoidance  ensure that a system
will never enter an unsafe state.
Safe, Unsafe, Deadlock State
 The Banker's Algorithm is a resource allocation and deadlock avoidance algorithm
that tests for the safety of the system when a process requests resources. It checks
whether allocating the requested resources will leave the system in a safe state or
not.
 Let's work through an example with the details provided:
 Number of processes (P): 5 (P0, P1, P2, P3, P4)
 Resource types:A, B, C
 Instances available for each resource: A: 10
B: 5
C: 7
To solve the Banker's Algorithm, we need to follow these
steps: Define the
Allocation, Maximum, Need, and Available matrices.
Check for a safe sequence using the safety algorithm.
Bankers Algorithm-Dead Lock Avoidance
 We will define the following matrices:
 Allocation Matrix: This represents the number of
resources of each type currently allocated to each process.
 Maximum Matrix: This represents the maximum number
of resources of each type that each process may need.
 Need Matrix: This is calculated as Need[i][j] = Maximum[i]
[j] - Allocation[i][j].
 AvailableVector: This represents the number of resources
of each type currently available.
Step 1: Define the Matrices

Example matrices
Consider a system with 5 resources p0 through p4 3 resource types
A(10 instances) B(5 instances) C(7 instances) Snap shot at time T0
Process Allocation
(A, B, C)
Maximum
(A, B, C)
Available
(A,B,C)
P0 (0, 1, 0) (7, 5, 3) (3,3,2)
P1 (2, 0, 0) (3, 2, 2)
P2 (3, 0, 2) (9, 0, 2)
P3 (2, 1, 1) (2, 2, 2)
P4 (0, 0, 2) (4, 3, 3)
 Need Matrix: Need=Maximum Allocation
−
The Available vector (resources currently available): Available = Total Resources -
Sum of Allocations:
A: 10 - (0 + 2 + 3 + 2 + 0) = 3
B: 5 - (1 + 0 + 0 + 1 + 0) = 3
C: 7 - (0 + 0 + 2 + 1 + 2) = 2
So,Available = (3, 3, 2).
Process Need (A, B, C)
P0 (7, 4, 3)
P1 (1, 2, 2)
P2 (6, 0, 0)
P3 (0, 1, 1)
P4 (4, 3, 1)
 To determine a safe sequence, we use the safety
algorithm:
 InitializeWork and Finish:
 Work = Available (3, 3, 2)
 Finish = [False, False, False, False, False]
 Find a process whose Need[i] is less than or equal to
Work and is not yet finished (Finish[i] is False). If such
a process is found, pretend to allocate its resources
toWork and mark it as finished.
Step 2: Safety Algorithm
Work = Work + Allocation of P1 = (3, 3, 2) + (2, 0, 0) = (5,
3, 2)
•Finish = [False, True, False, False, False]
•For P3: Need = (0, 1, 1) ≤ Work (5, 3, 2)
•Work = Work + Allocation of P3 = (5, 3, 2) + (2, 1, 1) = (7,
4, 3)
•Finish = [False, True, False, True, False]
•For P0: Need = (7, 4, 3) ≤ Work (7, 4, 3)
•Work = Work + Allocation of P0 = (7, 4, 3) + (0, 1, 0) = (7,
5, 3)
•Finish = [True, True, False, True, False]
•For P2: Need = (6, 0, 0) ≤ Work (7, 5, 3)
•Work = Work + Allocation of P2 = (7, 5, 3) + (3, 0, 2) = (10,
5, 5)
•Finish = [True, True, True, True, False]
•For P4: Need = (4, 3, 1) ≤ Work (10, 5, 5)
•Work = Work + Allocation of P4 = (10, 5, 5) + (0, 0, 2) =
(10, 5, 7)
•Finish = [True, True, True, True, True]
Since all processes are able to finish, the system is in a safe state.
The safe sequence is:
Safe Sequence: P1 -> P3 -> P0 -> P2 -> P4.
Thus, the system can allocate resources safely without leading to a
deadlock in the given scenario.
Bankers Algorithm
Assume that there are 5 processes, P0 through P4, and 4 types of resources. following system state:
 Max Instances of Resource Type A = 3 (2 allocated + 1 Available)
 Max Instances of Resource Type B = 17 (12 allocated + 5 Available)
 Max Instances of Resource Type C = 16 (14 allocated + 2 Available)
 Max Instances of Resource Type D = 12 (12 allocated + 0 Available)
Given Matrices
Allocation Matrix
(N0 of the allocated resources By a
process)
Max Matrix
Max resources that may be used by a
process
Available Matrix
Not Allocated
Resources
A B C D A B C D A B C D
P0 0 1 1 0 0 2 1 0 1 5 2 0
P1
1 2 3 1 1 6 5 2
P2 1 3 6 5 2 3 6 6
P3
0 6 3 2 0 6 5 2
P4
0 0 1 4 0 6 5 6
Total 2 12 14 12
Exercise 2:
If the system is in a safe state, can the following requests be granted,
why or why not? Please
also run the safety algorithm on each request as necessary.
a. P1 requests (2,1,1,0)
We cannot grant this request, because we do not have enough available
instances of resource A.
b. P1 requests (0,2,1,0)
There are enough available instances of the requested resources, so
first let’s
pretend to accommodate the request and see the system looks like:
Now we need to run the safety algorithm:
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
 Allocation=1 4 4 1
 Available= 1 3 1 0
 Need= 0 2 1 1
 Run the Safety Algorithm
 Finally, Need2(1,0,0,1) is less than
work.so we can also accommodate this.
Thus the system is in a safe state hence
the processes are run in the following
order: p0,p3,p4,p1,p2
UNIT – IV
STORAGE MANAGEMENT AND FILE
SYSTEMS INTERFACE
STORAGE MANAGEMENT:
 Storage management is the process of
 Controlling and coordinating computer
memory
 Assigning portions called blocks to various
running programs to optimize overall system
performance(Allocating Process)
 Freeing it for reuse when no longer needed
(Deallocating process)
 Motivation
 Keep several processes in memory to improve a
systems performance
 Allows Multiprogramming
 Instruction execution cycle
All computers have an instruction
execution cycle.
A basic instruction execution cycle can be
broken down into the following steps:
 Fetch cycle
 Execute cycle
Steps in Fetch/ExecuteCycle
 The instruction is fetched from memory addressed by
PC (Program Counter)
 PC is advanced to address the next instruction
 Instruction Decoder decodes the instruction held in
IR
 Instruction is then executed.
 Results are stored back to the memory
Memory Space Protection:
Memory protection is away to control
memory access rights on a computer.
SWAPPING:
 Swapping refers to moving entire
processes in and out of main memory.
 RoundRobin CPU-Scheduling
Algorithm
-Each process is provided a fix time to execute called
time slice or quantum
 Priority-based scheduling algorithms
-Each process is assigned apriority. Process with
highest priority is to be executed first and so on
-Processes with same priority are executed on first
come first serve basis
CONTIGUOUS MEMORY AL
LOCATION
 Memory Allocation
Memory Allocation is the process of
assigning blocks of memory on request for
the program execution.
 Memory Allocation mechanism
 Operating system uses the following
memory allocation mechanism.
 Single-partition allocation
 Multiple-partition allocation
Single-partition allocation:
 The operating system resides in the
low memory. The remaining
memory treated as a single
partition.
 This single partition is available for
userspace.
 Only one job can be loaded in this user
space
Multiple-partition allocation:
 Main memory is divided into a
number of fixed-sized partitions
where each partition should contain
only one process.
 When a partition is free, a process is
selected from the input queue and is
loaded into the free partition.
Memory Allocation:
1.Fixed Partitions Scheme:
 In this type of allocation, main memory is
divided into a number of fixed-sized
partitions where each partition should
contain only one process.
2.Variable Partition Scheme:
 Partitions are of variable length and number
.Process is allocated exactly as much
memory as required
Methods to assign processes to
partitions:
 There are two ways to assign processes
to partitions
 Use multiple queues
-Assign each process to the smallest partition
within which it will fit ,by using the scheduling
queues
 Use single queue
◦ In this method, only one ready queue is
present for scheduling the jobs for all the
blocks irrespective of size.
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
Dynamic Allocation Placement Algorithms
 The following algorithm is used to decide
which free block to allocate to a program
 First fit
 Allocate the first hole that is big enough;
 Process is placed in the first hole it can fit in.
 Best fit
 Allocate the smallest hole that is big.
 Worst-fit
 Allocate the largest hole, also search entire list.
Fragmentation:
 Fragmentation occurs when a system contains
total free memory to satisfy any request.
 Internal fragmentation
-Internal fragmentation is that the allocated
memory may be slightly larger than requested
memory.
 External fragmentation
-External fragmentation is done when the total
memory space exists to satisfy a request.
PAGING:
 Paging is a memory-management scheme
that permits the logical address space of a
process can be non contiguous.
 Pages
 Logical memory is also divided into
blocks of same size called pages
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
Memory Allocation in Paging
SEGMENTATION:
 Segmentation is the Memory
Management Scheme that supports user
view of memory.
 Logical address space is the collection of
segments
 Segmentation Architecture
 Segments are numbered and referred to by a segment
number ,thus a logical address consists of a tuple:
Segment Number Offset
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
Segmentation with Paging
 In Segmented Paging, the main memory is
divided into variable size segments which are
further divided into fixed size pages
 Segment Number → It points to the
appropriate Segment Number.
 Page Number → It Points to the exact page
within the segment
 Page Offset → Used as an offset within the
page frame
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
VIRTUALMEMORY
 Virtual memory is a technique that allows
execution of processes that are not
completely in the physical memory.
DEMAND PAGING:
 A demand-paging system is a paging system with
swapping.
 Initinitially loads pages only into memory (not the entire
process) as they are needed.
 Page Fault:
Page Fault is an interrupt that a rises upon a
reference to a page that is not in main
memory.
 Handling a Page Fault
Performance of Demand Paging
 The performance of Demand Paging is measured by
computing the effective access time for a demand
paged memory.
 Let p be probability of a Page Fault Rate 0 p 1.
 if p = 0 no page faults
 if p = 1,every reference is a fault
Effective AccessTime (EAT)
 The Effective AccessTime (EAT) is computed as follows
EAT= (1 –p) x memory access +p x page fault time.
Page fault time = page fault over head
+[swap page out ]
+swap page in
+restart over head)
PAGE REPLACEMENT
 Page replacement algorithm decides
which memory pages to be paged out to
disk (Swapout) to allocate memory for
another page
 Types of Page replacement
algorithm
 FIFO Page Replacement
 Optimal Page Replacement
 LRU Page Replacement
 FIFOPageReplacement
 FIFO stands for First-InFirst-Out
 Simple page replacement algorithm
 Chooses the oldest page in the memory
―
Referencestring: 1, 2,3,4, 1,2, 5,1,2,3, 4, 5
 Numberof page fault=9
 The page fault occurs for the given reference string is shown below
Faultrate=9/12 = 0.75
Optimal Page Replacement:
 Replace the page that will not be used for
the longest period of time in the future
Reference string: 1, 2,3,4, 1,2, 5,1,2,3, 4, 5
Number of page fault=7
Fault rate=7/12 = 0.58
LRU Page Replacement:
Replace the page that has not been used for
the longest period of time in past.
Reference string: 1, 2,3,4, 1,2, 5,1,2,3, 4, 5
Number of page fault=10
Fault rate=10/12 = 0.83
THRASHING
 If a process does not have enough
pages ,the page-fault rate is very high.
This leads to high paging activity called
Thrashing.
 A process is spending more time paging
than executing.
Working-Set Model
 The working set strategy is a variable-
allocation method with local scope based
on the assumption of locality of
references.
 The pages used by a process within a
window of time are called its working set.
 Page-Fault Frequency
 It establish acceptable page-fault rate
― ‖
 If actual rate too low, process loses frame
 If actual rate too high, process gains frame
Page-Fault Frequency (PFF) Strategy
 Define an upper bound U and lower bound L for page fault
rates.
 Allocate more frames to a process if fault rate is higher than
U.
 Allocate less frames if fault rate is less than L.
FILE CONCEPTS
• Named collection of related information that is recorded on
secondary storage such as magnetic disks, magnetic tapes
and optical disks.
 File System
 File system is the mechanism used to control
how data and program is stored and retrieved.
 File system consists of the following parts
◦ files
◦ directory structure
◦ Partitions
File Types
 indicate the internal structure of the file.
The Different types of file
◦ Data files
◦ Text file
◦ Source file
◦ Object file
◦ Executable file
 File Attributes
 Name
 Identifier
 Type
 Location
 Size
 Production
 Time, date, and user identification
File operations
 Create
 Write
 Read
 Reposition
 Delete
 Truncate
 Types of Lock
 Shared lock
A shared lock is a reader lock in that
several processes can acquire the lock
concurrently.
 Exclusive lock
An exclusive lock behaves like a writer lock;
only one process at a time can acquire
such a lock.
FILE ACCESS METHODS
 Sequential access
- information in the file is processed in order
• Direct/Random access
- accessing the records directly
• Indexed sequential access
- index is created for each file which
contains pointers to various blocks
DIRECTORY STRUCTURE
 Directory is a file system structure in which
computer files are stored.
 Directory is also known as folders.
 Files are organized by storing related files in
the same directory.
Logical Structure schemes:
 The different schemes for defining the logical
structure of a directory are
 Single-Level Directory
 Two-level Directory
 Tree-Structured Directories
 Acyclic-Graph Directories
 General Graph Directory
1. Single-Level Directory
• All files are contained in the same directory
Two-level Directory:
• One master file directory(MFD)
• Each user has their own UFD
Tree-Structured Directories
• An extension to the two-tiered directory structure It is
extended to a tree of arbitrary height
• Allows users to create their own subdirectories and to
organize their files
A cyclic-Graph Directories:
 Generalization of the tree-structured directory scheme
FILE SYSTEM MOUNTING
 Mounting is a process by which the
operating system makes files and directories
on a storage device .
 File must be opened before it is used, a file
system must be mounted before it can be
available to processes on the system.
FILE PROTECTION
The information stored in a computer
system must be kept safe from
 Physical damage (reliability)
 Improper access (protection)
Types of Access
 Read: Read from the file
 Write:Write or rewrite the file
 Execute:Load the file into memory and execute it
 Append:Write new information at the end of the file
 Delete: Delete the file and free its space for possible reuse
 List:List the name and attributes of the file
UNIT – 5
FILE SYSTEM
IMPLEMENTATION AND
MASS STORAGE
STRUCTURE
FILE SYSTEM STRUCTURE
 Disks provide the bulk of secondary
storage on which a file system is
maintained.
Characteristics
 A disk can be rewritten in place; it is
possible to read a block from the disk,
modify the block, and write it back into the
same place.
 A disk can access directly any given block
of information it contains.
Layered File System
 Application program layer
 Logical file system layer – Meta data(File
structure)
 File organization modules layer – Information
about files and logical blocks(Mapping)
 Basic file system layer – generates commands
for device driver(To read and write data)
 I/O control interface – consist of device
driver and interrupts.
 Physical h/w devices layer
FILE SYSTEM IMPLEMENTATION
 File-System Implementation are done by the
following
 On-disk structure
 In-memory structure
On-disk
 On-disk is the file system may contain
information about
 How to boot an operating system stored there
 The total number of blocks
 The number and location of free blocks
 The directory structure
 Individual files
On-disk structure:
 The On-disk structure include
 Boot control block
 Contain information needed by the system to boot an
operating system from the volume
 First block of a volume.
 Volume control block
 Contains volume details, such as the number of blocks in
the partition, size of the blocks, free block count and free-
block pointers, and free FCB count and FCB pointers.
 Directory structure
 Used to organize the files.
 FCB
 Contains the details about the file, including file
permissions, ownership, size, and location of the data
blocks. File data blocks
File permissions
File dates (create, access, write)
File owner, group, ACL
File Size
 In-memory Structure
 The structures may include the ones described
below
 In-memory mount table
 Contains information about each mounted volume
 In-memory directory-structure
 Holds the directory information of recently accessed
directories
 System-wide open-file table
 Contains a copy of the FCB of each open file as well as other
information
 Per-process open file table
 Contains a pointer to the appropriate entry in the system-wide
open file table as well as other information
 In-memory file-system structures for File
open.
 In-memory file-system structures for File
read
Directory Implementation
 Linear list of file names with pointer to the data blocks
◦ Simple to program
◦ Time-consuming to execute
 Linear search time
 Could keep ordered alphabetically via linked list or use
B+ tree
 HashTable – linear list with hash data structure
◦ Decreases directory search time
 Collisions – A collision is a situation where two file names
hash to the same location.Alternatively, a chained-overflow
hash table can be used to avoid collisions
Allocation methods
 Allocation methods is a methods used to
allocate space to the files for
-Utilizing the disk space effectively
-Accessing the files quickly
Methods
 Contiguous allocation
 Linked allocation
 Indexed allocation
Allocation Methods - Contiguous
 An allocation method refers to how disk blocks
are allocated for files:
 Contiguous allocation – each file occupies
set of contiguous blocks
◦ Best performance in most cases
◦ Simple – only starting location (block #) and
length (number of blocks) are required
◦ Problems include finding space for file,
knowing file size, external fragmentation, need
for compaction off-line (downtime) or
on-line
Contiguous Allocation
 Mapping from logical to physical
Allocation Methods - Linked
 Linked allocation – each file a
linked list of blocks
◦ File ends at nil pointer
◦ No external fragmentation
◦ Each block contains pointer to next
block
◦ No compaction, external fragmentation
Linked Allocation
File-Allocation Table
Allocation Methods - Indexed
 Indexed allocation
◦ Each file has its own index block(s) of
pointers to its data blocks
 Logical view
index table
Example of Indexed Allocation
Indexed Allocation – Mapping (Cont.)
Free-Space Management
 Maintaining the free-space list to keep track of free disk space.
 File system maintains free-space list to track available blocks/clusters
◦ (Using term “block” for simplicity)
 Bit vector or bit map (n blocks)
…
0 1 2 n-1
bit[i] =

1  block[i] free
0  block[i] occupied
The bit vector for this allocation is
00111100111111000110000001110000
 File Creation
◦ Search the free space list for the required
amount of space
◦ Space is removed from the free space list and
allocate it to the new file
 File Deletion
◦ Disk space is added to the free space list
Free-Space Management (Cont.)
 Bit map requires extra space
• Each block is represented by 1 bit. If the block is free the bit is 1 if the
block is allocated the bit is 0.
Linked Free Space List on Disk
 Linked list (free list)
 Cannot get contiguous
space easily
 No waste of space
 No need to traverse the
entire list (if # free blocks
recorded)
Free-Space Management (Cont.)
 Grouping
• A modification of the free list approach is to store the
addresses of n free blocks in the first free block.
• plus a pointer to next block that contains free-block-
pointers (like this one)
 Counting
 Keep address of first free block and count of following
free blocks
 Free space list then has entries containing addresses
and counts
Disk Scheduling
 Minimize seek time
 Seek time  seek distance
 Disk bandwidth is the total number
of bytes transferred, divided by the
total time between the first request
for service and the completion of the
last transfer
Disk Scheduling (Cont.)
 To service a request disk system requires that the
head to be moved the desired track, then a wait
for latency and finally transfer it
 Several algorithms exist to schedule the servicing
of disk I/O requests
1. FIFO
2. Shortest seek time first
3. Scan
4. Circular scan
5. LOOK
6. Circular LOOK
 The analysis is true for one or many
platters
 We illustrate scheduling algorithms with a
request queue (0-199)
98, 183, 37, 122, 14, 124, 65, 67
Head pointer 53
FCFS
Illustration shows total head movement of 640 cylinders
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
SSTF
 Shortest Seek Time First selects the
request with the minimum seek time
from the current head position
 SSTF scheduling is a form of SJF
scheduling
 Illustration shows total head movement
of 236 cylinders
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
SCAN
 The disk arm starts at one end of the
disk, and moves toward the other end,
servicing requests until it gets to the
other end of the disk, where the head
movement is reversed and servicing
continues.
 SCAN algorithm Sometimes called
the elevator algorithm
SCAN (Cont.)
Operating Systems- Dr.G.Sumathi AI & DS, KNCET
C-SCAN
 The head moves from one end of the disk
to the other, servicing requests as it goes
◦ When it reaches the other end, however, it
immediately returns to the beginning of the disk,
without servicing any requests on the return trip
 Treats the cylinders as a circular list that
wraps around from the last cylinder to the
first one
 Total number of cylinders?
C-SCAN (Cont.)
LOOK
• Similar to SCAN beginning
direction
• it reverses the direction
immediately, without going all the
way to the end of the disk
C-LOOK
 C-LOOK a version of C-SCAN
 Arm only goes as far as the last
request in each direction, then
reverses direction immediately,
without first going all the way to the
end of the disk
C-LOOK (Cont.)
LINUX
File system
 A Structured Collection of files on a disk
drive or a Partition
 Partition-segment of Memory and
Contains some Specific Data
Linux File System Sections
 The root directory(/)
 The Specific Data storage format
(EXT3,EXT4,BTRFS,XFS)
 A Partition or Logical volume having a
particular File System
Linux File System Structure
 Linux file system has a hierarchal file
structure as it contains a root directory
and its subdirectories.
 The data structure needs to support a
hierarchical directory structure
 Structure is used to describe the
available and used disk space for a
particular block- details about the files
such as file size, date & time of
creation, update, and last modified.
File system software
Implementation Architecture
Linux File System Features
 In Linux, the file system creates a tree
structure.
 All the files are arranged as a tree and
its branches.
 The topmost directory called the root
(/) directory.
 All other directories in Linux can be
accessed from the root directory.
• Specifying paths: Linux does not use the backslash () to separate
the components; it uses forward slash (/) as an alternative. For
example, as in Windows, the data may be stored in C: My
Documents Work, whereas, in Linux, it would be stored in /home/
My Document/ Work.
• Partition, Directories, and Drives: Linux does not use drive
letters to organize the drive as Windows does. In Linux, we cannot
tell whether we are addressing a partition, a network device, or an
"ordinary" directory and a Drive.
• Case Sensitivity: Linux file system is case sensitive. It
distinguishes between lowercase and uppercase file names. Such
as, there is a difference between test.txt and Test.txt in Linux. This
rule is also applied for directories and Linux commands.
• File Extensions: In Linux, a file may have the extension '.txt,' but it
is not necessary that a file should have a file extension. While
working with Shell, it creates some problems for the beginners to
differentiate between files and directories.
• Hidden files: Linux distinguishes between standard files and
hidden files, mostly the configuration files are hidden in Linux OS.
Usually, we don't need to access or read the hidden files. The
hidden files in Linux are represented by a dot (.) before the file
name (e.g., .ignore).
File system
 Computer network is used to support
RFS
 File transfer protocol(FTP) and Secure
shell protocol(SSP)
Client-server model:
1.Client
2.Server
3.Service
 Clients -mount remote file system from server
 Client open communication channel using IP
address of the remote host and port address
 Server opens to start service
 Network File system(NFS) – standard for
UNIX client server file sharing protocol
 Common Internet File system – WINDOWS
Failure modes
Reason for local file system failure
 Media fails where the file system is stored
 Corruption of directory structure
 Power cable and hard disk cable failure
 Disk controller failure
 Host adapter failure
Consistency semantics
 Related with file sharing
 When does the changes of original file reflect
to other users
1.Unix – Writes to open file immediately visible
2.Session - Writes to open file not visible. Once
the file is closed, the changes are visible only to
new sessions
3.Immutable – Becomes immutable and read
only
4.Transaction like semantics
Record blocking
 File is a collection of data records
1.Fixed blocking
2.Variable length spanned blocking –
records are packed into blocks without
wastage of space
3.Variable length unspanned – Large
wastage
THANKYOU

More Related Content

PPTX
OS UNIT1.pptx
PDF
osunit1ppt-23011904470yuoij4-685c22ef.pdf
PPTX
OS UNIT 1 PPT.pptx
PPTX
Advanced computer architecture lesson 1 and 2
PDF
Distributed Operating System_1
PDF
Operating System.pdf
PPT
Operating Systems with Storage and Process Management
PPT
Operating Systems _ Process & Storage Management
OS UNIT1.pptx
osunit1ppt-23011904470yuoij4-685c22ef.pdf
OS UNIT 1 PPT.pptx
Advanced computer architecture lesson 1 and 2
Distributed Operating System_1
Operating System.pdf
Operating Systems with Storage and Process Management
Operating Systems _ Process & Storage Management

Similar to Operating Systems- Dr.G.Sumathi AI & DS, KNCET (20)

PPT
Operating Systems Storage & Process Management
PDF
Operating System Concepts Presentation
PPTX
Os unit i
PPTX
Operating system
PPTX
OS UNIT 1 NOTES (1).pptxxdjhvcdkfshfkdhvjdsk
PPTX
Operating system and utility program LECTURE 8.pptx
PPTX
Operating systems
PPTX
CSE3120- Module1 part 1 v1.pptx
PPT
Introduction To operating System:
PPT
Introduction to Operating Systems - Mary Margarat
PDF
operating systems classification university
PPTX
Design Of Operating System_Lecture_OS_2.pptx
PDF
System Structure Notes : comprehensive study
DOCX
Introduction to Operating System
PPT
cs-intro-os.ppt
PDF
Os notes
PPTX
Operating System concepts
PDF
R20CSE2202-OPERATING-SYSTEMS .pdf
PPTX
Introduction to Operating Systems
PPT
Operating System
Operating Systems Storage & Process Management
Operating System Concepts Presentation
Os unit i
Operating system
OS UNIT 1 NOTES (1).pptxxdjhvcdkfshfkdhvjdsk
Operating system and utility program LECTURE 8.pptx
Operating systems
CSE3120- Module1 part 1 v1.pptx
Introduction To operating System:
Introduction to Operating Systems - Mary Margarat
operating systems classification university
Design Of Operating System_Lecture_OS_2.pptx
System Structure Notes : comprehensive study
Introduction to Operating System
cs-intro-os.ppt
Os notes
Operating System concepts
R20CSE2202-OPERATING-SYSTEMS .pdf
Introduction to Operating Systems
Operating System
Ad

Recently uploaded (20)

PPTX
Fundamentals of Mechanical Engineering.pptx
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
Soil Improvement Techniques Note - Rabbi
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
introduction to high performance computing
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
Artificial Intelligence
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PPTX
Feature types and data preprocessing steps
PPTX
Information Storage and Retrieval Techniques Unit III
Fundamentals of Mechanical Engineering.pptx
Management Information system : MIS-e-Business Systems.pptx
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
Categorization of Factors Affecting Classification Algorithms Selection
Soil Improvement Techniques Note - Rabbi
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Abrasive, erosive and cavitation wear.pdf
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
introduction to high performance computing
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
III.4.1.2_The_Space_Environment.p pdffdf
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Artificial Intelligence
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
distributed database system" (DDBS) is often used to refer to both the distri...
Feature types and data preprocessing steps
Information Storage and Retrieval Techniques Unit III
Ad

Operating Systems- Dr.G.Sumathi AI & DS, KNCET

  • 1. 20IT401-OPERATING SYSTEMS UNIT-I INTRODUCTION AND OPERATING SYSTEM STRUCTURES By Dr. G. Sumathi ASP/AI & DS Kongunadu College of Engineering and Technology
  • 2. What is Operating System? • Operating system is a program that controls the execution of application programs. • Interface between user and computer hardware.
  • 3.  Software types : - Application s/w - System s/w System s/w types: -To create program development environment ( TE, Compiler,Assembler, Debugger) -To create run time environment (Loader, Libraries, OS)
  • 4. MAINFRAME SYSTEMS  First computer used to handle many commercial scientific applications.  Large organizations for critical applications like bulk data processing for tasks.
  • 5. A. Batch /Early System  Early computers were physically large machine.  In these systems the user did not interact directly with the computer system.
  • 6. B. Multi-programmed System  Multi-programming concept increases CPU utilization by organization jobs.  The operating system keeps several jobs in memory.
  • 7. C.Time Sharing System  The time sharing system is also known as multi user systems.  The CPU executes multiple jobs by switching among them but the switches occurs so frequently that the user can interact with each program while it is running.
  • 8. PERSONAL COMPUTER SYSTEM / DESKTOP SYSTEM  Personal computer appeared in 1970‘s. They are microcomputers that are smaller & less expensive than mainframe systems.  At first file protection was not necessary on a personal machine. But when other computers 2nd other users can access the files on a pc file protection becomes necessary.  E.g : windows 98, windows 2000, Linux.
  • 9. MULTIPROCESSOR SYSTEMS  Multiprocessor operating system allows the multiple processors.  Main objective of using multiprocessor operating system is to consume high computing power and increase the execution speed of system.
  • 10. DISTRIBUTED SYSTEMS  A distributed system is a system whose components are located on different networked computers, which communicate and coordinate their actions by passing messages to one another.  processors do not share memory or a clock.  processor has its own local memory.
  • 11. Types: 1. Client/Server Systems:-client requests a resource and the server provides that resource 2. Peer to Peer Systems:-equal participants in data sharing
  • 12. Advantages of Distributed Systems  Resource sharing  Computation speed up  Reliability  Effective communication  Nodes can easily share data with other nodes.  More nodes can easily be added  Failure of one node does not lead to the failure of the entire distributed system.
  • 13.  Disadvantages of Distributed Systems  It is difficult to provide adequate security in distributed systems  Some messages and data can be lost in the network while moving from one node to another.  The database connected to the distributed systems is quite complicated  Overloading may occur in the network if all the nodes of the distributed system try to send data at once.
  • 14. CLUSTERED SYSTEMS  Clustered Operating Systems work similarly to Parallel Operating Systems as they have many CPUs.  Clustered systems are made by two or more individual systems but they are connected with each other.  Independent computer system along with shared storage medium and all systems perform all tasks together
  • 15. Types of Clustered System 1. Asymmetric Clustering System: -one node in the cluster system is getting as hot standby mode (monitors all functions ) 2. Symmetric Clustering System: -multiple nodes help to run all applications, and it monitors all nodes at same time. 3. Parallel Cluster System: - allows to multiple users to access similar data on the common shared storage system
  • 16. Advantages of Clustered System:  Clustered system provides much better performance  Clustered system is better fault tolerance system, if anyone node gets fail then entire system does not halt.  Clustered system has great scalability because we can easily add new node with this system. Disadvantages of Clustered System  It is more costly because it contains expensive hardware and its design.  Required multiple servers and other hardware components for making one  It is very hard to monitor and maintenance this system.
  • 17. REALTIME SYSTEMS  Multiple programs are being executed at the same time on a single processing core.  System that controls scientific experiments, medical imaging systems and some display systems are real time systems. Types: 1. Hard real time systems:- critical task has been completed on time 2. Soft real time systems: - critical task gets priority over other tasks
  • 18. HANDHELD SYSTEMS  Handheld systems include Personal Digital Assistants (PDAs), such as Cellular Telephones with connectivity to a network such as the Internet.  Handheld devices may use wireless technology such as BlueTooth, allowing remote access to e-mail and web browsing.
  • 19. HARDWARE PROTECTION  If a computer system has multiple users and allows the concurrent execution of multiple processes, then access to data must be regulated.  Mechanisms ensure that files, memory segments, CPU, and other resources can be operated on by only those processes that have gained proper authorization from the operating system.  For example, memory-addressing hardware ensures that a process can execute only within its own address space.
  • 20. Basic Elements  Processor - Controls the operation of the computer and performs its data processing functions.  Main memory - Stores data and programs.  I/O Module - Move data between the computer and its external environment.  System bus - Provides for communication among processors, main memory and I/O modules.
  • 22. Instruction Execution  A program consists of a set of instructions stored in memory .  Instruction execution takes place in CPU registers • processor reads (fetches) instructions from memory • processor executes each instruction Two steps:
  • 24. Instruction Fetch and Execute  The processor fetches the instruction from memory  Program counter (PC) holds address of the instruction to be fetched next PC is incremented after each fetch
  • 26. Interrupts • It is an event external to the currently executing process that cause a change in the normal flow of instruction execution. • They tell the CPU to stop its current activities and execute the appropriate part of the OS  Interrupt the normal sequencing of the processor  Provided to improve processor utilization
  • 28. Cache Memory  The cache memory is small, fast memory between the processor and main memory.  Cache memory is smaller, faster memory and it contains a portion of main memory.
  • 30. Direct Memory Access  Transfers the entire block of data directly to and from memory without going through the processor  processor is involved only at the beginning and end of the transfer  processor executes more slowly during a transfer when processor access to the bus is required  More efficient than interrupt-driven or programmed I/O
  • 31. OS services 1.Program development – provides facilities such as editors in creating programs 2.Program execution – loading program into memory, I/O devices and files initialization 3.Access to I/O devices – using reads and writes 4.Controlled access to files – protection mechanisms in accessing in multiuser system 5.System access – provide protection of resources
  • 32. OS services 6.Error detection and response – Hardware errors - such as a memory error, or a device failure or malfunction; Software errors - division by zero, attempt to access forbidden memory location. OS provides a response that clears the error condition 7.Accounting: A good OS will collect usage statistics for various resources and monitor performance parameters such as response time. ->To improve performance in future -> Billing in multiuser system
  • 34. System Calls  System calls provide an interface between running program and an operating system.  Typically written in a high-level language (C or C++)  A system call is an explicit request to kernel mode via software interrupt.  It is like procedure call but system call enters kernel.  All system call return an integer value.  In the kernel positive or 0 denote successful termination and negative value denotes error condition.
  • 35.  Three general methods are used to pass parameters to the operating system. 1. The simplest approach is to pass the parameters in registers.This is the approach taken by Linux and Solaris. 2. Parameters also can be placed, or pushed, onto the stack by the program and popped off the stack by the operating system. 3. The parameters are generally stored in a block, or table in memory, and the address of the block is passed as a parameter in a register
  • 36. API – System Call – OS Relationship
  • 37. Examples of Windows and Unix System Calls
  • 38. System Programs  Modern OS is a collection of system programs.  Provide application programming environment on hardware for program development and execution ◦ Some of them are simply user interfaces to system calls; others are considerably more complex Categories of system calls:  File management - Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories
  • 39.  Status information ◦ Some ask the system for info - date, time, amount of available memory, disk space, number of users ◦ Others provide detailed performance, logging, and debugging information ◦ Typically, these programs format and print the output to the terminal or other output devices ◦ Some systems implement a registry - used to store and retrieve configuration information
  • 40. Operating System Structure  General-purpose OS is very large program  Various structure ◦ Simple structure – MS-DOS ◦ More complex -- UNIX ◦ Layered – an abstraction ◦ Microkernel -Mach
  • 41. Simple Structure -- MS-DOS  Small and simple in size  In new versions – size increased  Application programs directly interact with BIOS driver(DA)
  • 42. Non Simple Structure -- UNIX UNIX – limited by hardware functionality, The UNIX OS consists of two parts ◦ Systems programs ◦ The kernel - Provides system calls for the file system, CPU scheduling, memory management
  • 44. Layered Approach  The operating system is divided into a number of layers (levels),  The bottom layer (layer 0), is the hardware;  the highest (layer N) is the user interface.  Functionality of each layer is fixed.  Each layer consist of data structure and set of routines  With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers  Each layer is using system calls for performing their function
  • 45. Kernel  Kernel is a software code that resides in the central core of a operating system.  Shell is outer part of OS and it interacts with user commands.  Kernel does not directly interact with user. It interacts with shell.  Kernel is the first part of OS loaded into memory and remains entire computer session.  Kernel code is in protected area in memory.  Kernel works in kernel space.  User performs in user space.  Memory – two areas 1. System area 2. User area
  • 46. VIRTUAL MACHINES:  Virtualization technology enables a single PC or server to simultaneously run multiple operating systems or multiple sessions of a single OS  The host operating system can support a number of virtual machines (VM),
  • 48. SYSTEM DESIGN AND IMPLEMENTATION: Design Goals:  The first problem in designing a system is to define goals and specifications.  At the highest level, the design of the system will be affected by the choice of hardware and the type of system.  User goals - system should be convenient to use, easy to learn and to use, reliable, safe, and fast  System goals.- system should be easy to design, implement, and maintain.
  • 49. Implementation:  Once an operating system is designed, it must be implemented.  Because operating systems are collections of many programs, written by many people over a long period of time, it is difficult to make general statements about how they are implemented.  Early operating systems were written in assembly language.  Now, although some operating systems are still written in assembly language, most are written in a higher-level language (C, C++, etc).
  • 50. UNIT 2 PROCESS MANAGEMENT Objectives:  To introduce the notion of a process -- a program in execution, which forms the basis of all computation  To describe the various features of processes, including scheduling, creation and termination, and communication  To explore interprocess communication using shared memory and message passing  To describe communication in client-server systems
  • 51. Process Concept  Process – a program in execution.  A process is the unit of work in a modern time-sharing system.  Multiple parts ◦ The program code, also called text section ◦ Stack containing temporary data  Function parameters, return addresses, local variables ◦ Data section containing global variables ◦ Heap containing memory dynamically allocated during run time
  • 52. Process State  As a process executes, it changes state ◦ new: The process is being created ◦ running: Instructions are being executed ◦ waiting: The process is waiting for some event to occur ◦ ready: The process is waiting to be assigned to a processor ◦ terminated: The process has finished execution
  • 54. Operating System Concepts Process Scheduling:  Job queue – set of all processes in the system.  Ready queue – set of all processes residing in main memory, ready and waiting to execute.  Device queues – set of processes waiting for an I/O device.Each device has own queue  Process is moved between the various queues.
  • 56. Schedulers  Long-term scheduler (or job scheduler): - selects which processes should be brought into the ready queue.  Medium term scheduler - Part of swapping function. - Removes process from memory for I/O - May lead to suspended state (disk).
  • 57. OPERATIONS ON PROCESSES Process Creation:  OS creates new process with specified attributes and identifiers.  The creating process is called a parent process, where as the new processes are called the children of that process
  • 58.  Parent process creates children processes, which, in turn create other processes, forming a tree of processes.  Resource sharing ◦ Parent and children share all resources. ◦ Children share subset of parent’s resources.  Execution ◦ Parent and children execute concurrently. ◦ Parent waits until children terminate.
  • 59. Process Creation (Cont.)  UNIX examples ◦ fork system call creates new process Void main() { fork(); } ◦ execve system call used after a fork to replace the process’ memory space with a new program.
  • 60. Process Termination  Process executes last statement and asks the operating system to decide it (exit).  Parent may terminate execution of children processes (abort). 1.Normal completion of operation 2.Memory is not available 3.Time slice expired 4.Parent termination 5.Failure of I/O 6.Request from parent process 7.Misuse of access rights
  • 61. COOPERATING PROCESSES  A process is independent if it cannot affect or be affected by the other processes executing in the system.  A process is cooperating if it can affect or be affected by the other processes executing in the system.
  • 62. Reason for cooperating processes  Information sharing  Computation speedup (By exec sub tasks parallel)  Modularity(dividing the system functions into separate processes or threads)  Convenience
  • 63. Producer – Consumer Problem:  A producer process produces information that is consumed by a consumer process.  For example, a print program produces characters that are consumed by the printer driver.A compiler may produce assembly code, which is consumed by an assembler.
  • 64.  To allow producer and consumer processes to run concurrently, we must have available a buffer of items that can be filled by the producer and emptied by the consumer.  unbounded-buffer: places no practical limit on the size of the buffer.  bounded-buffer : assumes that there is a fixed buffer size.
  • 65. Interprocess Communication (IPC)  Operating systems provide the means for cooperating processes to communicate with each other via an inter process communication (PC) facility.  IPC provides a mechanism to allow processes to communicate and to synchronize their actions.  IPC is best provided by a message passing system. COPY
  • 66.  Inter process communication is achieved through, 1. Shared Memory - memory shared among the processes 2. Message Passing – communicate and to synchronize their actions IPC facility provides two operations:  send(message)  receive(message)
  • 67. (a) Message passing. (b) shared memory
  • 68. THREADS – OVERVIEW  A thread is the basic unit of CPU utilization.  It is sometimes called as a lightweight process.  It consists of a thread ID, a program counter, a register set and a stack.
  • 69. User thread and Kernel threads User threads: -It uses user space for thread scheduling -Transparent to OS - Created by run time libraries and cannot execute privileged instructions - smaller and faster EX:POSIX pthreads, Mach C-threads
  • 70.  Kernel thread -Thread management is done by kernel. -OS supports KLT. -Threads are constructed and controlled by system calls. Ex:Windows 95/98/NT
  • 71. Multithreading models  In many applications,user level threads are mapped with kernel level threads. 1.One to one 2.Many to one 3.Many to many
  • 72. One to One  One user level thread is mapped with one kernel level thread.  For 3 UT,Kernel creates 3 KT  Ex:Windows 95/XP,LINUX
  • 73. Many to one  Many user level threads are mapped with one kernel level thread.  Single thread of control Ex: Green threads for SOLARIS
  • 74. Many to many  Many user level threads map with many kernel level threads  M-to-N thread mapping
  • 75. CPU SCHEDULING  Selects one process among the processes in memory that are ready to execute, and allocates the CPU to one of them.  CPU scheduling is the basis of multi- programmed operating systems. CPU-I/O Burst Cycle:  Process execution consists of a cycle of CPU execution and I/O wait.  Process execution begins with a CPU burst.
  • 76. CPU Scheduler:  Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed.  The selection process is carried out by the short-term scheduler (or CPU scheduler).  The ready queue is not necessarily a first-in, first-out (FIFO) queue. It may be a FIFO queue, a priority queue, a tree, or simply an unordered linked list.
  • 77. Preemptive Scheduling: A scheduling method that interrupts the processing of a process and transfers the CPU to another process. CPU scheduling decisions may take place under the following four circumstances: 1. When a process switches from the running state to the waiting state. 2. When a process switches from the running state to the ready state. 3. When a process switches from the waiting state to the ready state. 4. When a process terminates.  Under 1 & 4 scheduling scheme is non preemptive.  Otherwise the scheduling scheme is preemptive.
  • 78. Non-Preemptive Scheduling:  In non preemptive scheduling, once the CPU has been allocated a process, the process keeps the CPU until it releases the CPU either by termination or by switching to the waiting state.
  • 79. Dispatcher:  The dispatcher is the module that gives control of the CPU to the process selected by the short- term scheduler. This function involves: 1. Switching context 2. Switching to user mode 3. Jumping to the proper location in the user program to restart that program.
  • 80. SCHEDULING CRITERIA 1. CPU utilization: The CPU should be kept as busy as possible. CPU utilization may range from 0 to 100 percent. 2. Throughput: It is the number of processes completed per time unit. 3. Turnaround time: The interval from the time of submission of a process to the time of completion is the turnaround time. Turnaround time 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.
  • 81. 4. Waiting time: Waiting time is the sum of the periods spent waiting in the ready queue. 5. Response time: It is the amount of time it takes to start responding, but not the time that it takes to output that response.
  • 82. First Come First Serve CPU Process Scheduling in Operating Systems Example 1. S. No Process ID Process Name Arrival Time Bu rst Time 2. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 3. 1 P 1 A 0 9 4. 2 P 2 B 1 3 5. 3 P 3 C 1 2 6. 4 P 4 D 1 4 7. 5 P 5 E 2 3 8. 6 P 6 F
  • 83.  Non Pre Emptive Approach Gantt chart for the above Example 1 is:  Turn Around Time = Completion Time - Arrival Time  Waiting Time = Turn Around Time - Burst Time
  • 84. Solution to the Above Question Example 1 S. No Process ID Arriva l Time Burst Time Completion Time Turn Around Time Waiting Time 1 P 1 A 0 9 9 9 0 2 P 2 B 1 3 12 11 8 3 P 3 C 1 2 14 13 11 4 P 4 D 1 4 18 17 13 5 P 5 E 2 3 21 19 16 6 P 6 F 3 2 23 20 18
  • 85.  The Average Completion Time is:  Average CT = ( 9 + 12 + 14 + 18 + 21 + 23 ) / 6  Average CT = 97 / 6  Average CT = 16.16667  The Average Waiting Time is:  Average WT = ( 0 + 8 + 11 + 13 + 16 + 18 ) /6  Average WT = 66 / 6  Average WT = 11  The Average Turn Around Time is:  Average TAT = ( 9 + 11 + 13 + 17 + 19 +20 ) / 6  Average TAT = 89 / 6  Average TAT = 14.83334  This is how the FCFS is solved in Non Pre Emptive Approach.
  • 86. Pre Emptive Approach  Gantt chart for the above Example 1 is: S. No Process ID Arrival Time Burst Time Compl etion Time Turn Around Time Waiting Time 1 P 1 A 0 9 23 23 14 2 P 2 B 1 3 8 7 4 3 P 3 C 1 2 3 2 0 4 P 4 D 1 4 15 14 10 5 P 5 E 2 3 11 9 7 6 P 6 F 3 2 5 2 0
  • 87.  The Average Completion Time is:  Average CT = ( 23 + 8 + 3 + 15 + 11 + 5 ) / 6  Average CT = 65 / 6  Average CT = 10.83333  The Average Waiting Time is:  Average WT = ( 14 + 4 + 0 + 10 + 7 + 0 ) /6  Average WT = 35 / 6  Average WT = 5.83333  The Average Turn Around Time is:  Average TAT = ( 23 + 7 + 2 + 14 + 9 +2 ) / 6  Average TAT = 57 / 6  Average TAT = 9.5  This is how the FCFS is solved in Pre Emptive Approach.
  • 88. Shortest Job First CPU Scheduling Algorithm Examples for Shortest Job First ProcessID Arrival Time Burst Time _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ P0 1 3 P1 2 6 P2 1 2 P3 3 7 P4 2 4 P5 5 5
  • 89. Non Pre Emptive Shortest Job First CPU Scheduling Process ID Arrival Time Burst Time Completio n Time Turn Around Time TAT = CT - AT Waiting Time WT = TAT - BT P0 1 3 5 4 1 P1 2 6 20 18 12 P2 0 2 2 2 0 P3 3 7 27 24 17 P4 2 4 9 7 4 P5 5 5 14 10 5
  • 91. Average Completion Time: 1. Average Completion Time = ( 5 + 20 + 2 + 27 + 9 + 14 ) / 6 2. Average Completion Time = 77/6 3. Average Completion Time = 12.833 Average Waiting Time: 4. Average Waiting Time = ( 1 + 12 + 17 + 0 + 5 + 4 ) / 6 5. Average Waiting Time = 37 / 6 6. Average Waiting Time = 6.666 Average Turn Around Time: 7. Average Turn Around Time = ( 4 +18 + 2 +24 + 7 + 10 ) / 6 8. Average Turn Around Time = 65 / 6 9. Average Turn Around Time = 6.166
  • 92. Pre Emptive Approach Process ID Arrival Time Burst Time Completio n Time Turn Around Time TAT = CT - AT Waiting Time WT =TAT - BT P0 1 3 5 4 1 P1 2 6 17 15 9 P2 0 2 2 2 0 P3 3 7 24 21 14 P4 2 4 11 9 5 P5 6 2 8 2 0
  • 94. Average Completion Time 1. Average Completion Time = ( 5 + 17 + 2 + 24 + 11 +8 ) / 6 2. Average Completion Time = 67 / 6 3. Average Completion = 11.166 Average Turn Around Time 4. Average Turn Around Time = ( 4 +15 + 2 + 21 + 9 + 2 ) / 6 5. Average Turn Around Time = 53 / 6 6. Average Turn Around Time = 8.833 Average Waiting Time 7. Average Waiting Time = ( 1 + 9 + 0 + 14 + 5 + 0 ) /6 8. Average Waiting Time = 29 / 6 9. Average Waiting Time = 4.833
  • 95. Non Preemptive Priority Scheduling Process ID Priority Arrival Time Burst Time 1 2 0 3 2 6 2 5 3 3 1 4 4 5 4 2 5 7 6 9 6 4 5 4 7 10 7 10
  • 97. Proces s Id Priorit y Arriva l Time Burst Time Compl etion Time Turnar ound Time Waitin g Time Respo nse Time 1 2 0 3 3 3 0 0 2 6 2 5 18 16 11 13 3 3 1 4 7 6 2 3 4 5 4 2 13 9 7 11 5 7 6 9 27 21 12 18 6 4 5 4 11 6 2 7 7 10 7 10 37 30 18 27
  • 98. 1.Turn Around Time = Completion Ti me - Arrival Time 2.Waiting Time = Turn Around Time - Burst Time 3.AverageWaiting Time = (0+11+2+7+12+2+18)/7=52/7 Avg Waiting Time = (0+11+2+7+12+2+18)/7 = 52/7 units
  • 99. Preemptive Priority Scheduling Process Id Priority Arrival Time Burst Time 1 2(L) 0 1 2 6 1 7 3 3 2 3 4 5 3 6 5 4 4 5 6 10(H) 5 15 7 9 15 8
  • 101. 1.Turnaround Time = Completion Tim e - Arrival Time 2.Waiting Time = Turn Around Time - Burst Time  Avg Waiting Time = (0+14+0+7+1+25+16)/7 = 63/7 = 9 units
  • 102. Process Id Priority Arrival Time Burst Time Comple tion Time Turn around Time Waiting Time 1 2 0 1 1 1 0 2 6 1 7 22 21 14 3 3 2 3 5 3 0 4 5 3 6 16 13 7 5 4 4 5 10 6 1 6 10 5 15 45 40 25 7 9 6 8 30 24 16
  • 103. RR Scheduling Example Assume Time Quantum TQ = 5 S. No Process ID Arrival Time Burst Tim e _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1 P 1 0 7 2 P 2 1 4 3 P 3 2 15 4 P 4 3 11 5 P 5 4 20 6 P 6 4 9
  • 104. Ready Queue P1, P2, P3, P4, P5, P6, P1, P3, P4, P5, P6, P3, P4, P5
  • 106.  Average Completion Time 1. Average Completion Time = ( 31 +9 + 55 +56 +66 + 50 ) / 6 2. Average Completion Time = 267 / 6 3. Average Completion Time = 44.5  Average Waiting Time 1. Average Waiting Time = ( 5 + 26 + 5 + 42 + 42 + 37 ) / 6 2. Average Waiting Time = 157 / 6 3. Average Waiting Time = 26.16667  Average Turn Around Time 1. Average Turn Around Time = ( 31 + 8 + 53 + 53 + 62 + 46 ) / 6 2. Average Turn Around Time = 253 / 6 3. Average Turn Around Time = 42.16667
  • 107. CASE STUDY: LINUX SCHEDULING  the Completely Fair Scheduler (CFS) became the default Linux scheduling algorithm.  Scheduling in the Linux system is based on scheduling classes.  Each class is assigned a specific priority.  Equally divides the CPU time among all the processes
  • 108. Unit – 3 PROCESS SYNCHRONIZATION AND DEADLOCKS
  • 109. ProcessesTypes The two types of processes are  Cooperating Processes  Can affect or be affected by the execution of another process  A process that shares data with other processes or share a logical address space.  Independent Processes  Cannot affect or be affected by the execution of another process  A process that does not share data. INTRODUCTION :
  • 110.  The best example to see the cooperation between two processes is Producer Consumer problem.  It is also known as the bounded-buffer problem.  The problem contains two processes:  the producer and the consumer.  Both processes share a common, fixed-size buffer used as a queue.  Producer produces and consumer consumes. Example: Producer-Consumer Problem:
  • 111.  Types Unbounded-buffer: ◦ No practical limit on the size of the buffer ◦ Consumer may wait, producer never waits Bounded-buffer: ◦ Assumes that there is a fixed buffer size ◦ Consumer waits for new item, producer waits if buffer is full. Race Conditions: The situation where several processes access and manipulate shared data concurrently and the out come of execution depends on the particular order in which the access takes place are called race conditions
  • 112. Critical Section (CS)  Each process has a code segment, called critical section, in which the shared data is accessed.  When one process is executing in the critical section, no other process is to be allowed in its critical section.This is the problem of Critical Section Problem. CRITICAL SECTION PROBLEM:
  • 113. Types of Section:  Each process must request permission to enter its critical section. 1. Entry Section(ES)  Section of code implementing the request permission to enter the critical section. 2. Exit Section (LS)  Section of code to leave the critical section which follows Entry Section. 3. Remainder Section(RS)  Remaining code of the process after the critical section.
  • 114. Structure of process Pi do { entrysection Criticalsection exit section Remaindersection } while(1);
  • 115. 1.Mutual Exclusion  If process Pi is executing in its critical section, then no other processes can be executing in their critical sections 2. Progress  If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely ◦ If only one process wants to enter, it should be able to ◦ If two or more want to enter, one of them should succeed Solution to Critical Section Problem:
  • 116. 3. Bounded Waiting :  A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted.
  • 117.  Mutex is short for Mutual exclusion  Mutex lock is used to solve the critical- section problem Used to ensure exclusive access to data shared between threads Used to protect critical regions and thus prevent race conditions MUTEX LOCKS:
  • 118.  Illustration  A process must acquire the lock before entering a critical section using acquire () function releases the lock when it exits the critical section using release() function
  • 119. SEMOPHORES:  Semaphore is a synchronization tool (provided by the OS) that does not require busy waiting .  Semaphore is a variable that has an integer value  May be initialized to a non negative number  Wait operation decrements the semaphore value  Signal operation increments semaphore value SYNCHRONIZATION HARDWARE:
  • 120.  A semaphore S is an integer variable that ,apart from initialization ,can only be accessed through 2 atomic and mutually exclusive operations:  wait(S)-Originally called P(), from Dutch proberen to test. ―  signal(S) -Originally calledV(), from Dutch verhogen to ― increment.  Wait and Signal Operations  Busy-waiting implementation of these in divisible (atomic) operations: wait(S) { while(S <=0 ) ; S--; }
  • 122. Usage of Semaphore:  Two or more processes can cooperate by means of simple signals such that a process can be forced to stop at a specified place until it has received a specified signal. Usage1:Critical Section of n Processes Problem Shared data Semaphore mutex; Structure of Process Pi do { wait(mutex); critical section signal(mutex); Remainder section }while(1);
  • 123.  Usage2: synchronization of 2 processes inserting the following statements inP1 s1;signal(mutex); and the following statements in P2 wait(mutex)s2;
  • 124.  Deadlock is a situation that occurs when two processes are waiting for the other to complete before proceeding  Types of Deadlock  Process Deadlock  A process is deadlocked when it is waiting on an event which will never happen  System Deadlock  A system is deadlocked when one or more processes are deadlocked DEADLOCK
  • 125. System Model  System consists of resources  Resource types : 1.Reusable - Processor, memory space, I/O devices 2.Consumable – interrupts,messages  Each resource type Ri has Wi instances.  Each process utilizes a resource in sequence: ◦ request ◦ use ◦ release
  • 126. Deadlock Characterization  Mutual exclusion: only one process at a time can use a resource  Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes  No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task Deadlock can arise if four conditions hold simultaneously.
  • 127.  Circular wait: there exists a set {P0, P1, …, Pn} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0.
  • 128. Resource-Allocation Graph  V is partitioned into two types: ◦ P = {P1, P2, …, Pn}, the set consisting of all the processes in the system ◦ R = {R1, R2, …, Rm}, the set consisting of all resource types in the system  request edge – directed edge Pi  Rj  assignment edge – directed edge Rj  Pi A set of vertices V and a set of edges E.
  • 129. Resource-Allocation Graph (Cont.)  Process  Resource Type with 4 instances  Request edge : Pi requests instance of Rj  Claim edge : Pi is holding an instance of Rj Pi Pi Rj Rj
  • 130. Example of a Resource Allocation Graph
  • 131. Resource Allocation Graph With A Deadlock
  • 132. Graph With A Cycle But No Deadlock
  • 133. Deadlock solution ◦ Deadlock prevention-remove possibility of deadlock occurring ◦ Deadlock avoidance – Identifying safe and unsafe states ◦ Deadlock detection ◦ Deadlock recovery
  • 134. Deadlock Prevention  Mutual Exclusion – not required for sharable resources (e.g., read-only files); must hold for non-sharable resources  Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources Restrain the ways request can be made
  • 135. Deadlock Prevention (Cont.)  No Preemption – ◦ If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released  Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration
  • 136. Deadlock Avoidance  Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes
  • 137. Safe State  When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state  System is in safe state if there exists a sequence <P1, P2, …, Pn> of ALL the processes in the systems such that for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j < I
  • 138. Basic Facts  If a system is in safe state  no deadlocks  If a system is in unsafe state  possibility of deadlock  Avoidance  ensure that a system will never enter an unsafe state.
  • 140.  The Banker's Algorithm is a resource allocation and deadlock avoidance algorithm that tests for the safety of the system when a process requests resources. It checks whether allocating the requested resources will leave the system in a safe state or not.  Let's work through an example with the details provided:  Number of processes (P): 5 (P0, P1, P2, P3, P4)  Resource types:A, B, C  Instances available for each resource: A: 10 B: 5 C: 7 To solve the Banker's Algorithm, we need to follow these steps: Define the Allocation, Maximum, Need, and Available matrices. Check for a safe sequence using the safety algorithm. Bankers Algorithm-Dead Lock Avoidance
  • 141.  We will define the following matrices:  Allocation Matrix: This represents the number of resources of each type currently allocated to each process.  Maximum Matrix: This represents the maximum number of resources of each type that each process may need.  Need Matrix: This is calculated as Need[i][j] = Maximum[i] [j] - Allocation[i][j].  AvailableVector: This represents the number of resources of each type currently available. Step 1: Define the Matrices
  • 142.  Example matrices Consider a system with 5 resources p0 through p4 3 resource types A(10 instances) B(5 instances) C(7 instances) Snap shot at time T0 Process Allocation (A, B, C) Maximum (A, B, C) Available (A,B,C) P0 (0, 1, 0) (7, 5, 3) (3,3,2) P1 (2, 0, 0) (3, 2, 2) P2 (3, 0, 2) (9, 0, 2) P3 (2, 1, 1) (2, 2, 2) P4 (0, 0, 2) (4, 3, 3)
  • 143.  Need Matrix: Need=Maximum Allocation − The Available vector (resources currently available): Available = Total Resources - Sum of Allocations: A: 10 - (0 + 2 + 3 + 2 + 0) = 3 B: 5 - (1 + 0 + 0 + 1 + 0) = 3 C: 7 - (0 + 0 + 2 + 1 + 2) = 2 So,Available = (3, 3, 2). Process Need (A, B, C) P0 (7, 4, 3) P1 (1, 2, 2) P2 (6, 0, 0) P3 (0, 1, 1) P4 (4, 3, 1)
  • 144.  To determine a safe sequence, we use the safety algorithm:  InitializeWork and Finish:  Work = Available (3, 3, 2)  Finish = [False, False, False, False, False]  Find a process whose Need[i] is less than or equal to Work and is not yet finished (Finish[i] is False). If such a process is found, pretend to allocate its resources toWork and mark it as finished. Step 2: Safety Algorithm
  • 145. Work = Work + Allocation of P1 = (3, 3, 2) + (2, 0, 0) = (5, 3, 2) •Finish = [False, True, False, False, False] •For P3: Need = (0, 1, 1) ≤ Work (5, 3, 2) •Work = Work + Allocation of P3 = (5, 3, 2) + (2, 1, 1) = (7, 4, 3) •Finish = [False, True, False, True, False] •For P0: Need = (7, 4, 3) ≤ Work (7, 4, 3) •Work = Work + Allocation of P0 = (7, 4, 3) + (0, 1, 0) = (7, 5, 3) •Finish = [True, True, False, True, False] •For P2: Need = (6, 0, 0) ≤ Work (7, 5, 3) •Work = Work + Allocation of P2 = (7, 5, 3) + (3, 0, 2) = (10, 5, 5) •Finish = [True, True, True, True, False] •For P4: Need = (4, 3, 1) ≤ Work (10, 5, 5) •Work = Work + Allocation of P4 = (10, 5, 5) + (0, 0, 2) = (10, 5, 7) •Finish = [True, True, True, True, True] Since all processes are able to finish, the system is in a safe state. The safe sequence is: Safe Sequence: P1 -> P3 -> P0 -> P2 -> P4. Thus, the system can allocate resources safely without leading to a deadlock in the given scenario.
  • 146. Bankers Algorithm Assume that there are 5 processes, P0 through P4, and 4 types of resources. following system state:  Max Instances of Resource Type A = 3 (2 allocated + 1 Available)  Max Instances of Resource Type B = 17 (12 allocated + 5 Available)  Max Instances of Resource Type C = 16 (14 allocated + 2 Available)  Max Instances of Resource Type D = 12 (12 allocated + 0 Available) Given Matrices Allocation Matrix (N0 of the allocated resources By a process) Max Matrix Max resources that may be used by a process Available Matrix Not Allocated Resources A B C D A B C D A B C D P0 0 1 1 0 0 2 1 0 1 5 2 0 P1 1 2 3 1 1 6 5 2 P2 1 3 6 5 2 3 6 6 P3 0 6 3 2 0 6 5 2 P4 0 0 1 4 0 6 5 6 Total 2 12 14 12
  • 147. Exercise 2: If the system is in a safe state, can the following requests be granted, why or why not? Please also run the safety algorithm on each request as necessary. a. P1 requests (2,1,1,0) We cannot grant this request, because we do not have enough available instances of resource A. b. P1 requests (0,2,1,0) There are enough available instances of the requested resources, so first let’s pretend to accommodate the request and see the system looks like: Now we need to run the safety algorithm:
  • 149.  Allocation=1 4 4 1  Available= 1 3 1 0  Need= 0 2 1 1  Run the Safety Algorithm  Finally, Need2(1,0,0,1) is less than work.so we can also accommodate this. Thus the system is in a safe state hence the processes are run in the following order: p0,p3,p4,p1,p2
  • 150. UNIT – IV STORAGE MANAGEMENT AND FILE SYSTEMS INTERFACE
  • 151. STORAGE MANAGEMENT:  Storage management is the process of  Controlling and coordinating computer memory  Assigning portions called blocks to various running programs to optimize overall system performance(Allocating Process)  Freeing it for reuse when no longer needed (Deallocating process)
  • 152.  Motivation  Keep several processes in memory to improve a systems performance  Allows Multiprogramming  Instruction execution cycle All computers have an instruction execution cycle. A basic instruction execution cycle can be broken down into the following steps:  Fetch cycle  Execute cycle
  • 153. Steps in Fetch/ExecuteCycle  The instruction is fetched from memory addressed by PC (Program Counter)  PC is advanced to address the next instruction  Instruction Decoder decodes the instruction held in IR  Instruction is then executed.  Results are stored back to the memory
  • 154. Memory Space Protection: Memory protection is away to control memory access rights on a computer.
  • 155. SWAPPING:  Swapping refers to moving entire processes in and out of main memory.
  • 156.  RoundRobin CPU-Scheduling Algorithm -Each process is provided a fix time to execute called time slice or quantum  Priority-based scheduling algorithms -Each process is assigned apriority. Process with highest priority is to be executed first and so on -Processes with same priority are executed on first come first serve basis
  • 157. CONTIGUOUS MEMORY AL LOCATION  Memory Allocation Memory Allocation is the process of assigning blocks of memory on request for the program execution.  Memory Allocation mechanism  Operating system uses the following memory allocation mechanism.  Single-partition allocation  Multiple-partition allocation
  • 158. Single-partition allocation:  The operating system resides in the low memory. The remaining memory treated as a single partition.  This single partition is available for userspace.  Only one job can be loaded in this user space
  • 159. Multiple-partition allocation:  Main memory is divided into a number of fixed-sized partitions where each partition should contain only one process.  When a partition is free, a process is selected from the input queue and is loaded into the free partition.
  • 160. Memory Allocation: 1.Fixed Partitions Scheme:  In this type of allocation, main memory is divided into a number of fixed-sized partitions where each partition should contain only one process. 2.Variable Partition Scheme:  Partitions are of variable length and number .Process is allocated exactly as much memory as required
  • 161. Methods to assign processes to partitions:  There are two ways to assign processes to partitions  Use multiple queues -Assign each process to the smallest partition within which it will fit ,by using the scheduling queues  Use single queue ◦ In this method, only one ready queue is present for scheduling the jobs for all the blocks irrespective of size.
  • 163. Dynamic Allocation Placement Algorithms  The following algorithm is used to decide which free block to allocate to a program  First fit  Allocate the first hole that is big enough;  Process is placed in the first hole it can fit in.  Best fit  Allocate the smallest hole that is big.  Worst-fit  Allocate the largest hole, also search entire list.
  • 164. Fragmentation:  Fragmentation occurs when a system contains total free memory to satisfy any request.  Internal fragmentation -Internal fragmentation is that the allocated memory may be slightly larger than requested memory.  External fragmentation -External fragmentation is done when the total memory space exists to satisfy a request.
  • 165. PAGING:  Paging is a memory-management scheme that permits the logical address space of a process can be non contiguous.  Pages  Logical memory is also divided into blocks of same size called pages
  • 169. SEGMENTATION:  Segmentation is the Memory Management Scheme that supports user view of memory.  Logical address space is the collection of segments  Segmentation Architecture  Segments are numbered and referred to by a segment number ,thus a logical address consists of a tuple: Segment Number Offset
  • 171. Segmentation with Paging  In Segmented Paging, the main memory is divided into variable size segments which are further divided into fixed size pages  Segment Number → It points to the appropriate Segment Number.  Page Number → It Points to the exact page within the segment  Page Offset → Used as an offset within the page frame
  • 173. VIRTUALMEMORY  Virtual memory is a technique that allows execution of processes that are not completely in the physical memory.
  • 174. DEMAND PAGING:  A demand-paging system is a paging system with swapping.  Initinitially loads pages only into memory (not the entire process) as they are needed.
  • 175.  Page Fault: Page Fault is an interrupt that a rises upon a reference to a page that is not in main memory.
  • 176.  Handling a Page Fault
  • 177. Performance of Demand Paging  The performance of Demand Paging is measured by computing the effective access time for a demand paged memory.  Let p be probability of a Page Fault Rate 0 p 1.  if p = 0 no page faults  if p = 1,every reference is a fault Effective AccessTime (EAT)  The Effective AccessTime (EAT) is computed as follows EAT= (1 –p) x memory access +p x page fault time. Page fault time = page fault over head +[swap page out ] +swap page in +restart over head)
  • 178. PAGE REPLACEMENT  Page replacement algorithm decides which memory pages to be paged out to disk (Swapout) to allocate memory for another page  Types of Page replacement algorithm  FIFO Page Replacement  Optimal Page Replacement  LRU Page Replacement
  • 179.  FIFOPageReplacement  FIFO stands for First-InFirst-Out  Simple page replacement algorithm  Chooses the oldest page in the memory ― Referencestring: 1, 2,3,4, 1,2, 5,1,2,3, 4, 5  Numberof page fault=9  The page fault occurs for the given reference string is shown below Faultrate=9/12 = 0.75
  • 180. Optimal Page Replacement:  Replace the page that will not be used for the longest period of time in the future Reference string: 1, 2,3,4, 1,2, 5,1,2,3, 4, 5 Number of page fault=7 Fault rate=7/12 = 0.58
  • 181. LRU Page Replacement: Replace the page that has not been used for the longest period of time in past. Reference string: 1, 2,3,4, 1,2, 5,1,2,3, 4, 5 Number of page fault=10 Fault rate=10/12 = 0.83
  • 182. THRASHING  If a process does not have enough pages ,the page-fault rate is very high. This leads to high paging activity called Thrashing.  A process is spending more time paging than executing.
  • 183. Working-Set Model  The working set strategy is a variable- allocation method with local scope based on the assumption of locality of references.  The pages used by a process within a window of time are called its working set.
  • 184.  Page-Fault Frequency  It establish acceptable page-fault rate ― ‖  If actual rate too low, process loses frame  If actual rate too high, process gains frame Page-Fault Frequency (PFF) Strategy  Define an upper bound U and lower bound L for page fault rates.  Allocate more frames to a process if fault rate is higher than U.  Allocate less frames if fault rate is less than L.
  • 185. FILE CONCEPTS • Named collection of related information that is recorded on secondary storage such as magnetic disks, magnetic tapes and optical disks.  File System  File system is the mechanism used to control how data and program is stored and retrieved.  File system consists of the following parts ◦ files ◦ directory structure ◦ Partitions
  • 186. File Types  indicate the internal structure of the file. The Different types of file ◦ Data files ◦ Text file ◦ Source file ◦ Object file ◦ Executable file
  • 187.  File Attributes  Name  Identifier  Type  Location  Size  Production  Time, date, and user identification File operations  Create  Write  Read  Reposition  Delete  Truncate
  • 188.  Types of Lock  Shared lock A shared lock is a reader lock in that several processes can acquire the lock concurrently.  Exclusive lock An exclusive lock behaves like a writer lock; only one process at a time can acquire such a lock.
  • 189. FILE ACCESS METHODS  Sequential access - information in the file is processed in order • Direct/Random access - accessing the records directly • Indexed sequential access - index is created for each file which contains pointers to various blocks
  • 190. DIRECTORY STRUCTURE  Directory is a file system structure in which computer files are stored.  Directory is also known as folders.  Files are organized by storing related files in the same directory.
  • 191. Logical Structure schemes:  The different schemes for defining the logical structure of a directory are  Single-Level Directory  Two-level Directory  Tree-Structured Directories  Acyclic-Graph Directories  General Graph Directory 1. Single-Level Directory • All files are contained in the same directory
  • 192. Two-level Directory: • One master file directory(MFD) • Each user has their own UFD
  • 193. Tree-Structured Directories • An extension to the two-tiered directory structure It is extended to a tree of arbitrary height • Allows users to create their own subdirectories and to organize their files
  • 194. A cyclic-Graph Directories:  Generalization of the tree-structured directory scheme
  • 195. FILE SYSTEM MOUNTING  Mounting is a process by which the operating system makes files and directories on a storage device .  File must be opened before it is used, a file system must be mounted before it can be available to processes on the system.
  • 196. FILE PROTECTION The information stored in a computer system must be kept safe from  Physical damage (reliability)  Improper access (protection) Types of Access  Read: Read from the file  Write:Write or rewrite the file  Execute:Load the file into memory and execute it  Append:Write new information at the end of the file  Delete: Delete the file and free its space for possible reuse  List:List the name and attributes of the file
  • 197. UNIT – 5 FILE SYSTEM IMPLEMENTATION AND MASS STORAGE STRUCTURE
  • 198. FILE SYSTEM STRUCTURE  Disks provide the bulk of secondary storage on which a file system is maintained. Characteristics  A disk can be rewritten in place; it is possible to read a block from the disk, modify the block, and write it back into the same place.  A disk can access directly any given block of information it contains.
  • 200.  Application program layer  Logical file system layer – Meta data(File structure)  File organization modules layer – Information about files and logical blocks(Mapping)  Basic file system layer – generates commands for device driver(To read and write data)  I/O control interface – consist of device driver and interrupts.  Physical h/w devices layer
  • 201. FILE SYSTEM IMPLEMENTATION  File-System Implementation are done by the following  On-disk structure  In-memory structure On-disk  On-disk is the file system may contain information about  How to boot an operating system stored there  The total number of blocks  The number and location of free blocks  The directory structure  Individual files
  • 202. On-disk structure:  The On-disk structure include  Boot control block  Contain information needed by the system to boot an operating system from the volume  First block of a volume.  Volume control block  Contains volume details, such as the number of blocks in the partition, size of the blocks, free block count and free- block pointers, and free FCB count and FCB pointers.  Directory structure  Used to organize the files.  FCB  Contains the details about the file, including file permissions, ownership, size, and location of the data blocks. File data blocks File permissions File dates (create, access, write) File owner, group, ACL File Size
  • 203.  In-memory Structure  The structures may include the ones described below  In-memory mount table  Contains information about each mounted volume  In-memory directory-structure  Holds the directory information of recently accessed directories  System-wide open-file table  Contains a copy of the FCB of each open file as well as other information  Per-process open file table  Contains a pointer to the appropriate entry in the system-wide open file table as well as other information
  • 204.  In-memory file-system structures for File open.
  • 205.  In-memory file-system structures for File read
  • 206. Directory Implementation  Linear list of file names with pointer to the data blocks ◦ Simple to program ◦ Time-consuming to execute  Linear search time  Could keep ordered alphabetically via linked list or use B+ tree  HashTable – linear list with hash data structure ◦ Decreases directory search time  Collisions – A collision is a situation where two file names hash to the same location.Alternatively, a chained-overflow hash table can be used to avoid collisions
  • 207. Allocation methods  Allocation methods is a methods used to allocate space to the files for -Utilizing the disk space effectively -Accessing the files quickly Methods  Contiguous allocation  Linked allocation  Indexed allocation
  • 208. Allocation Methods - Contiguous  An allocation method refers to how disk blocks are allocated for files:  Contiguous allocation – each file occupies set of contiguous blocks ◦ Best performance in most cases ◦ Simple – only starting location (block #) and length (number of blocks) are required ◦ Problems include finding space for file, knowing file size, external fragmentation, need for compaction off-line (downtime) or on-line
  • 209. Contiguous Allocation  Mapping from logical to physical
  • 210. Allocation Methods - Linked  Linked allocation – each file a linked list of blocks ◦ File ends at nil pointer ◦ No external fragmentation ◦ Each block contains pointer to next block ◦ No compaction, external fragmentation
  • 213. Allocation Methods - Indexed  Indexed allocation ◦ Each file has its own index block(s) of pointers to its data blocks  Logical view index table
  • 214. Example of Indexed Allocation
  • 215. Indexed Allocation – Mapping (Cont.)
  • 216. Free-Space Management  Maintaining the free-space list to keep track of free disk space.  File system maintains free-space list to track available blocks/clusters ◦ (Using term “block” for simplicity)  Bit vector or bit map (n blocks) … 0 1 2 n-1 bit[i] =  1  block[i] free 0  block[i] occupied
  • 217. The bit vector for this allocation is 00111100111111000110000001110000
  • 218.  File Creation ◦ Search the free space list for the required amount of space ◦ Space is removed from the free space list and allocate it to the new file  File Deletion ◦ Disk space is added to the free space list
  • 219. Free-Space Management (Cont.)  Bit map requires extra space • Each block is represented by 1 bit. If the block is free the bit is 1 if the block is allocated the bit is 0.
  • 220. Linked Free Space List on Disk  Linked list (free list)  Cannot get contiguous space easily  No waste of space  No need to traverse the entire list (if # free blocks recorded)
  • 221. Free-Space Management (Cont.)  Grouping • A modification of the free list approach is to store the addresses of n free blocks in the first free block. • plus a pointer to next block that contains free-block- pointers (like this one)  Counting  Keep address of first free block and count of following free blocks  Free space list then has entries containing addresses and counts
  • 222. Disk Scheduling  Minimize seek time  Seek time  seek distance  Disk bandwidth is the total number of bytes transferred, divided by the total time between the first request for service and the completion of the last transfer
  • 223. Disk Scheduling (Cont.)  To service a request disk system requires that the head to be moved the desired track, then a wait for latency and finally transfer it  Several algorithms exist to schedule the servicing of disk I/O requests 1. FIFO 2. Shortest seek time first 3. Scan 4. Circular scan 5. LOOK 6. Circular LOOK
  • 224.  The analysis is true for one or many platters  We illustrate scheduling algorithms with a request queue (0-199) 98, 183, 37, 122, 14, 124, 65, 67 Head pointer 53
  • 225. FCFS Illustration shows total head movement of 640 cylinders
  • 227. SSTF  Shortest Seek Time First selects the request with the minimum seek time from the current head position  SSTF scheduling is a form of SJF scheduling  Illustration shows total head movement of 236 cylinders
  • 230. SCAN  The disk arm starts at one end of the disk, and moves toward the other end, servicing requests until it gets to the other end of the disk, where the head movement is reversed and servicing continues.  SCAN algorithm Sometimes called the elevator algorithm
  • 233. C-SCAN  The head moves from one end of the disk to the other, servicing requests as it goes ◦ When it reaches the other end, however, it immediately returns to the beginning of the disk, without servicing any requests on the return trip  Treats the cylinders as a circular list that wraps around from the last cylinder to the first one  Total number of cylinders?
  • 235. LOOK • Similar to SCAN beginning direction • it reverses the direction immediately, without going all the way to the end of the disk
  • 236. C-LOOK  C-LOOK a version of C-SCAN  Arm only goes as far as the last request in each direction, then reverses direction immediately, without first going all the way to the end of the disk
  • 238. LINUX File system  A Structured Collection of files on a disk drive or a Partition  Partition-segment of Memory and Contains some Specific Data
  • 239. Linux File System Sections  The root directory(/)  The Specific Data storage format (EXT3,EXT4,BTRFS,XFS)  A Partition or Logical volume having a particular File System
  • 240. Linux File System Structure  Linux file system has a hierarchal file structure as it contains a root directory and its subdirectories.  The data structure needs to support a hierarchical directory structure  Structure is used to describe the available and used disk space for a particular block- details about the files such as file size, date & time of creation, update, and last modified.
  • 242. Linux File System Features  In Linux, the file system creates a tree structure.  All the files are arranged as a tree and its branches.  The topmost directory called the root (/) directory.  All other directories in Linux can be accessed from the root directory.
  • 243. • Specifying paths: Linux does not use the backslash () to separate the components; it uses forward slash (/) as an alternative. For example, as in Windows, the data may be stored in C: My Documents Work, whereas, in Linux, it would be stored in /home/ My Document/ Work. • Partition, Directories, and Drives: Linux does not use drive letters to organize the drive as Windows does. In Linux, we cannot tell whether we are addressing a partition, a network device, or an "ordinary" directory and a Drive. • Case Sensitivity: Linux file system is case sensitive. It distinguishes between lowercase and uppercase file names. Such as, there is a difference between test.txt and Test.txt in Linux. This rule is also applied for directories and Linux commands. • File Extensions: In Linux, a file may have the extension '.txt,' but it is not necessary that a file should have a file extension. While working with Shell, it creates some problems for the beginners to differentiate between files and directories. • Hidden files: Linux distinguishes between standard files and hidden files, mostly the configuration files are hidden in Linux OS. Usually, we don't need to access or read the hidden files. The hidden files in Linux are represented by a dot (.) before the file name (e.g., .ignore).
  • 244. File system  Computer network is used to support RFS  File transfer protocol(FTP) and Secure shell protocol(SSP) Client-server model: 1.Client 2.Server 3.Service
  • 245.  Clients -mount remote file system from server  Client open communication channel using IP address of the remote host and port address  Server opens to start service  Network File system(NFS) – standard for UNIX client server file sharing protocol  Common Internet File system – WINDOWS
  • 246. Failure modes Reason for local file system failure  Media fails where the file system is stored  Corruption of directory structure  Power cable and hard disk cable failure  Disk controller failure  Host adapter failure
  • 247. Consistency semantics  Related with file sharing  When does the changes of original file reflect to other users 1.Unix – Writes to open file immediately visible 2.Session - Writes to open file not visible. Once the file is closed, the changes are visible only to new sessions 3.Immutable – Becomes immutable and read only 4.Transaction like semantics
  • 248. Record blocking  File is a collection of data records 1.Fixed blocking 2.Variable length spanned blocking – records are packed into blocks without wastage of space 3.Variable length unspanned – Large wastage

Editor's Notes

  • #22: A program to be executed by a processor consists of a set of instructions stored in memory. In its simplest form, instruction processing consists of two steps: The processor reads ( fetches ) instructions from memory one at a time and executes each instruction. Program execution consists of repeating the process of instruction fetch and instruction execution. Instruction execution may involve several operations and depends on the nature of the instruction.
  • #23: The processing required for a single instruction is called an instruction cycle. Using a simplified two-step description, the instruction cycle is depicted in Figure 1.2 . The two steps are referred to as the fetch stage and the execute stage. Program execution halts only if the processor is turned off, some sort of unrecoverable error occurs, or a program instruction that halts the processor is encountered.
  • #24: At the beginning of each instruction cycle, the processor fetches an instruction from memory. Typically, the program counter (PC) holds the address of the next instruction to be fetched. Unless instructed otherwise, the processor always increments the PC after each instruction fetch so that it will fetch the next instruction in sequence (i.e., the instruction located at the next higher memory address).
  • #28: Although cache memory is invisible to the OS, it interacts with other memory management hardware. Furthermore, many of the principles used in virtual memory schemes (discussed in Chapter 8 ) are also applied in cache memory. On all instruction cycles, the processor accesses memory at least once, to fetch the instruction, and often one or more additional times, to fetch operands and/ or store results. The rate at which the processor can execute instructions is clearly limited by the memory cycle time (the time it takes to read one word from or write one word to memory). This limitation has been a significant problem because of the persistent mismatch between processor and main memory speeds: Over the years, processor speed has consistently increased more rapidly than memory access speed. We are faced with a trade-off among speed, cost, and size. Ideally, main memory should be built with the same technology as that of the processor registers, giving memory cycle times comparable to processor cycle times. This has always been too expensive a strategy. The solution is to exploit the principle of locality by providing a small, fast memory between the processor and main memory, namely the cache.
  • #29: Cache and main memory illustration. Figure 1.16b depicts the use of multiple levels of cache. The L2 cache is slower and typically larger than the L1 cache, and the L3 cache is slower and typically larger than the L2 cache.
  • #30: The processor then continues with other work. It has delegated this I/O operation to the DMA module, and that module will take care of it. The DMA module transfers the entire block of data, one word at a time, directly to or from 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 needs to take control of the bus to transfer data to and from memory. Because of this competition for bus usage, there may be times when the processor needs the bus and must wait for the DMA module. Note that this is not an interrupt; the processor does not save a context and do something else. Rather, the processor pauses for one bus cycle (the time it takes to transfer one word across the bus). The overall effect is to cause the processor to execute more slowly during a DMA transfer when processor access to the bus is required. Nevertheless, for a multiple-word I/O transfer, DMA is far more efficient than interrupt-driven or programmed I/O.
  • #31: A multicore computer, also known as a chip multiprocessor , combines two or more processors (called cores) on a single piece of silicon (called a die). Typically, each core consists of all of the components of an independent processor, such as registers, ALU, pipeline hardware, and control unit, plus L1 instruction and data caches. In addition to the multiple cores, contemporary multicore chips also include L2 cache and, in some cases, L3 cache. The motivation for the development of multicore computers can be summed up as follows. For decades, microprocessor systems have experienced a steady, usually exponential, increase in performance. This is partly due to hardware trends, such as an increase in clock frequency and the ability to put cache memory closer to the processor because of the increasing miniaturization of microcomputer components. Performance has also been improved by the increased complexity of processor design to exploit parallelism in instruction execution and memory access. In brief, designers have come up against practical limits in the ability to achieve greater performance by means of more complex processors. Designers have found that the best way to improve performance to take advantage of advances in hardware is to put multiple processors and a substantial amount of cache memory on a single chip. A detailed discussion of the rationale for this trend is beyond our scope, but is summarized in Appendix C .
  • #32: A multicore computer, also known as a chip multiprocessor , combines two or more processors (called cores) on a single piece of silicon (called a die). Typically, each core consists of all of the components of an independent processor, such as registers, ALU, pipeline hardware, and control unit, plus L1 instruction and data caches. In addition to the multiple cores, contemporary multicore chips also include L2 cache and, in some cases, L3 cache. The motivation for the development of multicore computers can be summed up as follows. For decades, microprocessor systems have experienced a steady, usually exponential, increase in performance. This is partly due to hardware trends, such as an increase in clock frequency and the ability to put cache memory closer to the processor because of the increasing miniaturization of microcomputer components. Performance has also been improved by the increased complexity of processor design to exploit parallelism in instruction execution and memory access. In brief, designers have come up against practical limits in the ability to achieve greater performance by means of more complex processors. Designers have found that the best way to improve performance to take advantage of advances in hardware is to put multiple processors and a substantial amount of cache memory on a single chip. A detailed discussion of the rationale for this trend is beyond our scope, but is summarized in Appendix C .