Module 1
Module 1
MODULE-I
TEXT BOOK:
1. Operating System Concepts – Abraham Silberschatz, Peter Baer Galvin, Greg
Gagne, 8th edition, Wiley-India, 2009.
2. Mordern Operating Systems – Andrew S. Tanenbaum, 3rd Edition, PHI
3. Operating Systems: A Spiral Approach – Elmasri, Carrick, Levine, TMH Edition
DISCLAIMER
“THIS DOCUMENT DOES NOT CLAIM ANY ORIGINALITY AND CANNOT BE USED AS A
SUBSTITUTE FOR PRESCRIBED TEXTBOOKS. THE INFORMATION PRESENTED HERE IS
MERELY A COLLECTION FROM DIFFERENT REFERENCE BOOKS AND INTERNET
CONTENTS. THE OWNERSHIP OF THE INFORMATION LIES WITH THE RESPECTIVE
AUTHORS OR INSTITUTIONS.”
S/W: Set of instructions or programs instructing a computer to do specific
task
OPEARARING SYSTEM(OS):
It is the system software.
Operating System
Computer H/W
Resource like CPU,Memory,
I/O devices
1. Convenience/User friendly
2ndary Goal:
1. process management
2. Memory management
3. .I/O device management
4. File management
5. Network Management
6. Security and Protection
Types of Operating system
1. Batch operating system
2. Time sharing operating system
3. Distributed operating system
4. Network operating system
5. Real time operating system
6. Multiprogramming /Multiprocessing /Multitasking OS
1. Common I/P and O/P devices were card readers and tape drivers
2. Users prepare a job which consist of the program, I/p data and
control information
3. I/p job is given in the form of punch cards and results also appear in
the form of punch card after processing.
4. So OS was very simple, always presents in the memory. Major task is
to translate the control from one job to another.
Computer system
JOB
CPU
Program
I/P data
+
I/P JOB OS O/P
Control
Instruction
User program
Disadvantages ?
Batch processing:
1. Jobs with similar needs are batched together and executed through
the processor s as a group.
2. Operators sorts jobs as a deck of punch cards into batch with similar
needs COMPUTER
Ex: Fortran batch, COBOL batch. R
Batch1 Batch2 CPU
User1->job1 Job7 2Job4
User2->job2 Operator +
Job5 Job14
……. I/P OS
O/P
Usern> jobn Job6 Job3
User
program
Advantages:
1. In a batch processing job excute one after another , saving time from
activities like loading compiler
2. During a batch execution no manual intervention is needed.
Disadvantages:
1. Memory limitation
2. Interaction of I/P and O/P devices directly with CPU.
3. CPU utilization is idle.
Spooling :( simultaneous peripheral operation online)
1. I/P and O/P devices are relatively slow compare to CPU (
digital)
2. In spooling , data is stored first onto disk and then CPU interact
with Disk(digital) via main memory
3. Spooling is capable of overlapping I/O operations of one job
with CPU operations of other jobs.
Computer
CPU
+
+
Main Memory
I/P device
O/P device
DISK
VIEW of SPOOLING
Advantages:
Disadvantages:
COMPUTER SYTEM
M.M
OS
P1
P2
P3
CPU
P4
Advantage:
WORD
E-MAIL OS CPU
Browser
Multiprocessing Operating System
1. Two or more CPU within a single computer in close communication
sharing the system bus, memory and other I/O devices
2. Different process may run of different CPU, true parallel execution.
3. Systematic: One OS control all CPU, each CPU has equal rights.
4. Asymmetric :Master slave architecture .System task on one
processor and application on other as one CPU will handle all H/W
interrupt as I/O devices, they are easy to design but less efficient.
Advantage:
1. Increase throughput
2. Increase reliability
3. Cost saving
4. True parallel processing
5. Better efficiency
Disadvantages:
1. More Complex
2. Overhead as coupling reduce throughput
3. Large main memory
MEMORY
FUNCTION OF OPERATING SYSTEM
1. Initial Loading of program
2. Process management
3. Main memory management
4. File Management
5. I/O system Management
6. 2ndary storage management
7. Networking
8. Protection or Security
9. Command – Interpreter System
2. Process management
4. File management:
Computer can store information on several different types of physical
media: magnetic tape, magnetic disk and optical disk. Each medium
is controlled by a device such as disk drive or tap drive those has
unique characteristics. These characteristics include access speed,
capacity,transfer rate and access method( :sequential or random).
7. Networking:
9. Command Interpretation:
System calls provide the interface between a process & the OS.
These are usually available in the form of assembly language
instruction. Some systems allow system calls to be made directly
from a high level language program like C, BCPL and PERL etc.
systems calls occur in different ways depending on the computer
in use. System calls can be roughly grouped into 5 major
categories.
1. Process control
2. File manipulation
3. Device Management
4. Information Maintenance
5. Communication
System calls provide an interface to the service made
available by an Operating system.
Application
Privileged
mode OS
User mode
Kernel
Kernel
CPU, Memory, I/O
Mode
H/W
Ex: of Systems call sequence for writing a simple program to read data from one file and copy them to
another file.
Accept Input
Accept Input
If file Exists,ABORT
Terminate Normally
Ex:2 The standard C library provides a portion of system call interface for many versions of UNIX and
LINUX. Let’s assume a C program invokes the printf() statement. The C library intercepts this call and
invokes the necessary system call(or calls) in the operating system-in this instance, the write() system
call. The C library takes the value returned by write () and passes it back to the user program
#include<stdio.h>
int main()
printf(“hello”);
Return 0;
User Mode
Standard C library
Kernel Mode
Write()
Write()
System call
1. Process Control:
End, abort: A running program needs to be able to has its
execution either normally (end) or abnormally (abort).
Load, execute: A process or job executing one program
may want to load and executes another program.
Create Process, terminate process: There is a system call
specifying for the purpose of creating a new process or job
(create process or submit job). We may want to terminate a
job or process that we created (terminates process, if we
find that it is incorrect or no longer needed).
Get process attributes, set process attributes: If we create
a new job or process we should able to control its
execution. This control requires the ability to determine &
reset the attributes of a job or processes (get process
attributes, set process attributes).
Wait time: After creating new jobs or processes, we may
need to wait for them to finish their execution (wait time).
Wait event: We may wait for a specific event to occur (wait
event).
Example of system call: fork(),exit(),kill(),nice()
Allocate and free memory:
2. File Manipulation:
Create file, delete file: We first need to be able to create &
delete files. Both the system calls require the name of the
file & some of its attributes.
Open file, close file: Once the file is created, we need to
open it & use it. We close the file when we are no longer
using it.
Read, write, reposition file: After opening, we may also
read, write or reposition the file (rewind or skip to the end
of the file).
Get system data, set system data: Other system calls may
return information about the system like number of current
users, version number of OS, amount of free memory etc.
Shared Memory
Process B M 1
2
2 Process B
Kernel M
Kernel
2. Layered Structure
3. Microkernel systems
Kernel Mode
Monolithic Kernel
System Hardware
Advantages of monolithic Kernels:
Monolithic kernels are quite fast. The code is accessible to all the
components of the operating system and this code can be executed
without much restriction making the overall system fast.
Monolithic kernels provide direct communication between
components which makes the system more efficient to work
Disadvantages:
Monolithic kernels are more prone to errors and bugs as user process
runs in same address spaces as that of kernel. Also maintaining the
code also becomes difficult.
Harder to port because of dependency on code.
Adding /removing any feature or functionality in monolithic system are
quite difficult and often require rewriting and recompiling the whole
code again.
2. Layered Structure
The first layer based operating system was proposed by E.W dijkstra and
his team. In layered approach the operating system consist of several
layers where each layer has a well defined functionality and each layer can
be designed, coded and tested independently. The layers are arranged in
increasing order of abstraction, means the lowest layer(0) interacts and
deals with the underlying hardware and topmost layer(N) provides an
interface to the application programs and user program(process).Each
layer relies on the service of the layers below it. The communication takes
place only between adjacent layers. For example: layer 3 can request a
service from layer 2 immediately below it and it can provide service only to
the layer 4 immediately above .Each layer knows what services are
provided by the layer above it but the details as how these services are
provided are hidden. The different layers can be file management layer,
memory management layer, communication management layer, User
program layer etc.
USER PROCESS Application Utilities ………………….
Program
USER MODE
Layer N
..............................
Layer 0 Hardware
The more the layers, the more is overhead incurred to maintain them.
If the functionality is not properly divided among the layers, it might
be possible that one layer has too much functionality. If this happens
that layer may be overburden leading to overall low system
performance.
3. Microkernel systems:
MICRO KERNEL
SYSTEM HARDWARE
Advantages:
Disadvantages:
Ex: # include<stdio.h>
int main()
{
char str[ ]=”Hello”;
printf(“%s”, str);
}
gcc hello.c
/[Link]
Process
Executable
([Link])
A program in execution
Present in the RAM
Stack
Heap
Data
Text
Max size
Ex: #include<stdio.h> Stack
#include< stdlib.h>
int calls;
void fact(int a,int *b)
{
calls++;
if(a==1) return;
*b=*b*a;;
fact(a-1,b);
}
Heap
int main()
{
int n,*m;
scanf(“%d”,&n); Data(static &global)
m=malloc(sizeof(int);
*m=1; Text
fact(n,m)
printf(“%dfactorial=%d”,n,*m);
free(m);
MAP of a process
max size is fixed and decided by OS
When a process executes, it passes through different states. These stages may
differ in different operating systems and the names of these states are not
standardized.
1. New: The process is being created.
2. Running: Instructions are being executed.
3. Waiting: The process is waiting for some event to occur (Ex: I/O completion
or reception of a signal)
4. Ready: The process is waiting to be assigned to a processor.
5. Terminated: The process has finished execution.
Admitted Interrupt
New Terminated
exit
I/O or
I/O or event event wait
completion
Waiting
Process Control Block(PCB) OR Task control Block (TCB):
A process control block is a data structure maintained by OS for every process.
The PCB is identified by an integer process ID (PID).It contains many pieces of
information associated with a specific process. These are:
1. Process state: The state may be New, Ready, Running, Waiting, Halted and
so on.
2. Process privileges: This is required to allow /disallow access to system
resources.
3. Program Counter: The counter indicates the address of the next instruction
to be executed for this process
4. Process ID: Unique identification for each of the process in the O/S
5. CPU register: Various CPU registers (AC,index registers,stack pointer ,GPR
registers) where process need to be stored for execution for running
[Link] with the program counter ,this state information must be saved
when an interrupt occurs, to allow the process to be continued correctly
afterward( refer figure 3.4)
6. CPU-scheduling information: information includes process priority and
other scheduling information which is required to schedule the process.
7. Memory –management information: this includes the information of page
table, memory limits, segment table depending on memory system used by
the O/S.
8. Accounting Information:This includes the amount of CPU and real time
used, time limits, account numbers, process ID and so on.
9. I/O status information: Information includes the list of I/O devices allocated
to process, a list of open files and so on.
The PCB is maintained for a process throughout its life time and is deleted
once the process terminated
Process ID
State
Program counter
CPU registers
CPU –scheduling
Information
Memory-Management
Accounting information
………….
PCB Lay out
PCB LAYOUT
Process scheduling
Scheduling Queues:
Job Queue: As process enters the system, they are put into job queue,
which consist of all processes in the system.
Ready Queue: The process that are residing in main memory and are
ready and waiting to execute are kept on a list called the ready queue.
1. Long-Term schedulers
2. Short-Term schedulers.
3. Medium-term schedulers.
When the scheduler switches the CPU from executing one process to execute
another, the state from current running process is stored into the process control
block. After this ,the state for the process to run next is loaded from its own PCB
and used to set the PC,registers and so on. At that point, the 2nd process can start
executing.(refer fig.3.4)
Context switches are automatically intensive since register and memory state
must be saved and restored. To avoid the amount of context switching time,
some H/W systems employs two or more sets of processor registers when the
process is switched, the following information is stored for later use.
[Link] [Link] information [Link] and limit registers use [Link] used
register [Link] state 6.I/O state information [Link] information
CPU Scheduling
CPU scheduling is the process which allows one process to use the CPU while the
execution of another process is on hold (waiting state) due to unavailability of any
resource like I/O etc, thereby making full use of CPU. The aim of CPU scheduling is
to make the system efficient, fast and fair.
Whenever the CPU becomes idle, the operating system must select one of
processes in the ready queue to be executed .The selection process is carried out
by the short-term scheduler.(or CPU scheduler).
The scheduler selects from among the processes in the memory that are ready to
execute and allocates the CPU to one of them.
CPU scheduling deals with the problem of deciding which of the processes in the
ready queue is to be allowed first to CPU.
Dispatcher:
Another component involved in the CPU scheduling function is the 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 from where it left last
time.
1. Non-preemptive Scheduling:
Under non-preemptive scheduling, once the CPU has been allocated to a
process, and then process keeps the CPU until it releases the CPU either by
terminating or by switching to the waiting state.
Ex: Microsoft 3.1 ,Apple Macintosh O/S
2. Preemptive scheduling:
Under this scheduling the process has to leave the CPU forcefully on the
basis of some criteria like running to ready and waiting to ready state
transaction.
Ex: At times to run a certain task that has a higher priority before another
task although it is running. Therefore the running task is interrupted for
some time and resumed later when the priority task has finished its
execution.
CPU scheduling decisions may take place under the following four
circumstances :->
1. When a process switches from the running state to the waiting state
(For I/O request or invocation of wait for the termination of one of the child
processes)
i.e. non primitive
2. When a process switches from the running state to the ready state
3. When a process switches from the waiting to ready state (Ex: Completion of
I/O i.e preemptive)
Scheduling Criteria:
There are many different criteria’s to check when considering the best
scheduling algorithm:
1. CPU utilization
We want to keep the CPU as busy as possible. CPU utilization may
range from 0 to 100%.In a real system, CPU usage should range from 40
%( Light –loaded) to 90 % (heavily loaded).
2. Throughput:
It is the total no. of processes completed per unit time. This may range
10/sec to 1/hour depending on the specific process.(length of process).
3. Turnaround Time:
It is the amount of time taken to execute a particular process i.e the
interval from time of submission of the process to the time of
completion of the process.
Turnaround Time (TAT) = finishing time-arrival time.
(Turnaround time is the sum of periods spend waiting to get
memory,waiting in the ready queue ,executing on the CPU and doing I/O
operation)
TAT=Completion Time (C.T)- Arrival time(A.T)
4. Waiting Time:
Waiting time is the sum of periods spends waiting in the ready queue.
Waiting Time(WT)=starting time-arrival time
(The CPU scheduling algorithms doesn’t affect the amount the time
during which a process executes or does I/O operation, it affects only
the amount of time that a process spends waiting in ready queue)
Waiting Time=TAT-BT (Burst time)
Burst time/execution time/running time=It is the time, process require
for running on CPU
5. Response Time:
Amount of Time it takes from when a request was submitted until the
first response is produced.
It is the time, the first response and not the completion of process
execution.
Response Time(RT)=First response-Arrival Time.
(i.e time between a process enters ready queue and get scheduled on
the CPU for the first time)
Optimization criteria:
1. Maximum CPU utilization
2. Maximum throughput
3. Minimum Turnaround Time
4. Minimum waiting Time
5. Minimum response time
LOAD B
CPU burst
ADD B
Read a file
Executing instruction
CPU Burst
Store X
P1 3
P2 5
P3 2
P4 4
Using FCFS Algorithm find the average waiting time and average
turnaround Time (TAT) if order is P1, P2, P3, and P4.
Solution: Gantt chart will be:
Finish time
P1 P2 P3 P4
Staring time
0 3 8 10 14
Problem2: Find the Average waiting time and Average TAT of the
following: Process Arrival Time CPU Burst
Process Arrival Time CPU Burst
P1 0 16
P1 0 16
P2 5 7
P2 5 7
P3 10 14
P3 10 14
P4 4 8
P4 4 8
P5 7 12
P5 7 12
P1 P4 P2 P5 P3 GANTT CHART
Solution:
0 16 24 31 43 57
Process Arrival Time (A.T) CPU Burst (B.T) Completion Time (C.T) Turn Around Time (TAT) Waiting Time (W.T)
P1 A 0 16 16 16 0
P2 5 7 31 26 19
P3 10 14 57 47 33
P4 4 8 24 20 12
P5 7 12 43 36 24
WT = T.A.T - B.T
Advantage of FCFS:
Convoy effect:
A. B.
[Link] A.T B.T [Link] A.T B.T
1 0 20 1 0 2
2 1 2 2 1 2
3 2 2 3 2 20
P1 P2 P3
P1 P2 P3
0 2 4 24
0 20 22 24
Q.: Find the Average waiting time and Average TAT of the following:
3 2 1
4 3 2
5 4 5
1 6 4
idle
2 2 5 Gantt chart
P4 P2 P3 p5 p6 p1
3 3 3
0 1 2 7 10 12 18 22
4 1 1
2 2 5 7 5 0
3 3 3 10 7 4
4 1 1 2 1 0
5 4 2 12 8 6
6 5 6 18 13 7
If the arrival time of the processes are same/matching then
schedule the process which has lowest process ID
Gantt chart
[Link] A.T B.T
1 8 2 Idl p5 p2 p6 p3 p1 p4
Idle
2 3 4
3 7 6 0 2 3 7 8 14 16 19
4 10 3
6 3 1 1 8 2 16 8 6
2 3 4 7 4 0
3 7 6 14 7 1
WT = T.A.T - B.T 4 10 3 19 9 6
6 3 1 8 5 4
P1 21 Gantt
P4 P2 P3 p1
chart
P2 3
0 2 5 11 32
P3 6
P4 2
P1 21 32 43 11
P2 3 5 5 2
P3 6 11 11 5
P4 2 02 2 0
If the arrival time for processes are different, which means all the processes are
not available in the ready queue at time ‘0’ and some jobs arrive after some time,
in such situation, sometimes process with the short burst time have to wait for
the current process’s execution to finish, because in non-preemptive SJF
scheduling, on arrival of a process with short duration, the existing job/process‘s
execution is not halted /stopped to execute the short job first.
This leads to the problem of starvation where a shorter process has to wait
for a long time until the current longer process gets executed .This happen
if shorter jobs keep coming, but this can be solved using the concept of
aging. Aging is used to gradually increase the priority of a task, based
on its waiting time in the ready queue.
Q.1 Find the avg waiting time and TAT as per following using SJF Non-
preemptive
1 1 7
2 2 5
3 3 1
4 4 2
5 5 8
P1 P3 P4 p2 p5 1 1 7 8 7 0
Gantt chart: Idle
2 2 5 16 14 9
0 1 8 9 11 16 24
3 3 1 9 6 5
4 4 2 11 7 5
5 5 8 24 19 11
T.A.T= C.T-A.T=8-1=7 and so on Avg W.T=(0+9+5+5+11)/5=30/5=6ms
Q2. If the bust times of the process are same /matching then schedule the
process which has lowest arrival time
[Link] A.T B.T
Using Non-preemptive SJF find avg W.T. ?
1 6 1
2 3 3
3 4 6
4 1 5
5 2 2
6 5 1
0 1 6 7 8 10 13 19
Q. find out the avg waiting time and avg turn around time of the following process
(using SJF non preemptive algorithm)
Process A.T B.T
P1 0 8 Avg W.T= 7.75 ms
P2 1 4
P3 2 9
P4 3 5
Preemptive shortest job first
In preemptive shortest job–first scheduling , jobs are put into ready queue as they
arrive, but as a process with short burst time arrives ,the existing process is
preempted or removed from execution and shorter job is executed first.
1 0 9 1 0 9 8
Solution: step1
2 1 4 2 1 4
3 2 1 P1 3 2 1
0 1
Step2 8 1 0 9 8
1 0 9
2 1 4 3 2 1 4 3 x
3 2 1 x 3 2 1 x
P1 P2 p3
P1 P2 p3 p2
0 1 2 3
0 1 2 3 6
[Link] A.T B.T
Step4. 1 0 9 8 x
[Link] A.T B.T C.T TAT WT
2 1 4 3 x Step-5
1 0 9 14 14 5
3 2 1 x
2 1 4 6 5 1
3 2 1 3 1 0
Gantt chart P1 P2 p3 p2 p1
[Link] AT BT [Link] AT BT
8 X
1 0 9 Solution: 1 0 9
3 X
2 1 4 2 1 4
3 2 9 3 2 9 X
P1 P2 P2 P1 P3
Gantt chart
0 1 2 5 13 22
[Link] AT BT CT TAT WT
1 0 9 13 13 4
2 1 4 5 4 0
3 2 9 22 20 11
Average WT=(4+0+11)/3=15/3=5ms
Average TAT=(13+4+20)/3=37/3=12.3ms
Priority scheduling Algorithm
In this scheduling a priority is associated with each process and the CPU is
allocated to process with highest priority.
Q.1
[Link] A.T B.T priority Criteria=priority
1 0 4 4 Mode=Non-preemptive
2 1 5 5
3 2 1 7 High
4 3 2 2
5 4 3 1 Low
6 5 6 6
P1 p3 P6 p2 p4 p5 Gantt chart
Solution:
0 4 5 11 16 18 21
1 0 4 4 4 4 0
2 1 5 5 16 15 10
3 2 1 7 5 3 2
4 3 2 2 18 15 13
5 4 3 1 21 17 14
6 5 6 6 11 6 0
Q2. Priority based: preemptive:
5 2 2 2 14
0 1 2 3 8 10 12 14 15 18
2
7 3 2 3 10
High 8 4 3 5 08
Avg wt time= 13+10+50+11+6=45/6=7.5 ms
5 5 3 1 15
6 6 4 2 12
Q3. Find the Avg waiting time of following using preemptive priority based
scheduling
5 1 1 4 P4 p1 p1 p3 p5 p6 p5 p3 p1 p2
2 2 2 5
0 1 2 3 4 5 8 9 14 16 21
6 3 3 6
4 4 0 1 Avg W.T=?
7 5 4 2
8 6 5 3
Disadvantages:
Disadvantages:
The average waiting time under the round robin policy is quite long
No Process
completion
Execute process for T.Q
Process
T.Q expires termination
Process
No completed
yes
execution
Q1. Find out the Average waiting time of following using R-R scheduling (given
TQ=2)
Ready queue
Solution:
[Link] A.T B.T P1 P2 P3 P1 P4 P5 P2 P6 p5 p2 p6 p5
1 0 4
2 1 5 P1 P2 P3 P1 P4 P5 P2 P6 p5 p2 p6 p5
3 2 2 0 2 4 6 8 9 11 13 15 17 18 19 21
4 3 1
6 5 3 1 0 4 08 08 04
2 1 5 18 17 12
3 2 2 06 04 02
4 3 1 09 06 05
5 4 6 21 17 11
6 5 3 19 14 11
Avg TAT=66/6=11ms
Ready queue
Step 1: P1 p2 p3 p1
[Link] A.T B.T
1 0 4 2
Gantt chart P1
2 1 5 3 1
0 2
3 2 2
4 3 1 Ready queue
5 4 6 4 2
step2 P1 p2 p3 p1 p4 p5 p2
6 5 3 1
Gantt chart P1 p2
Step7 0 2 4
0 2 4 6 8 9 11 13 Gantt chart P1 p2 p3
Step-8 0 2 4 6
P1 p2 p3 p1 p4 p5 p2 p6 p5p2 p6
Step 4 P1 p2 p3 p1 p4 p5 p2 p6
P1 p2 p3 p1 p4 p5 p2 p6
0 2 4 6 8 9 11 13 15 P1 p2 p3 p1
0 2 4 6 8
Step9 P1 p2 p3 p1 p4 p5 p2 p6 p5p2 p6 p5
Step 5 P1 p2 p3 p1 p4 p5 p2 p6
P1 p2 p3 p1 p4 p5 p2 p6 p5
P1 p2 p3 p1 p4
0 2 4 6 8 9 11 13 15 17
0 2 4 6 8 9
P1 p2 p3 p1 p4 p5 p2 p6 p5p2 p6 p5
Step-10
Step6 P1 p2 p3 p1 p4 p5 p2 p6 p5
P1 p2 p3 p1 p4 p5 p2 p6 p5 p2 p6 p5
0 2 4 6 8 9 11 13 15 17 18 19 21 P1 p2 p3 p1 p4 p5
0 2 4 6 8 9 11
Objectives of R-R scheduling:
If the time quantum is less , then the number context switches will
increase and response time will be less
If the quantum time is large , then number of context switches will
decrease and response time will be more
If the time quantum is very-very large , then this algorithm generates as
FCFS algorithm
Round robin is used to decrease the response time.
EX:
C.S
P1 P2 P3 P4 P1
0 2 4 6 8 10
T.Q CS
response decrease
T.Q CS
Response increase
T.Q FCFS
Q. Consider a system which has ‘n ‘process sharing the CPU in round robin
Fashion. The context switching time is ‘s’ units. Then what must be the time
quantum ‘q’ such that each process is guaranteed to get its turn at the CPU for
every ‘t’ seconds of time.
There are two ways to service processes in the queue. They two ways are.
1. The processes in the highest priority queue are serviced first by CPU
(according to their scheduling algorithm).When highest priority queue
becomes empty; CPU switches to medium priority queue and service
all the processes. When medium priority queue is empty, CPU finally
switches to the lowest priority queue and services all the processes
till that queue becomes empty.
One problem in this approach is that processes in the low priority
queue can be serviced until the queue above it with higher priority
becomes empty. This can result in starvation for the processes in the
lower priority queues. Queues are assigned CPU based on the
priority. Process in high priority queue are
serviced first by CPU, then process in
medium priority queue and finally process
in the lowest priority queue
R-R scheduling OR
Alternatively each queue is allocated
System process High Priority queue certain amount of CPU time
R-R scheduling
FCFS scheduling
If a process has a long CPU burst not to be completed within time slice, it is
moved to lower priority queue. This approach leaves I/O bound and
interactive processes in the higher priority queues. Also, a process that
waits too long in a lower priority queue may be moved to a higher priority
Queue .This aging technique prevents lower priority processes from being
starved for CPU time
Process
Queue priority1 allocated
Maintained FIFO Process N …… process2 process1 Queue allocated CPU for given
Manner time slice (quantum)
CPU one
by one
Process
Queue priority2 allocated
Process N ….. process2 process1 Queue allocated CPU for given time
Lowest queue
maintained FIFO slice (quantum)
CPU one
Manner
by one
Q. Consider a system which has CPU bound process which requires Burst
time of 40 time units. Multilevel feedback queue scheduling is used .The
time quantum is 2 units and it will be incremented by 5 units in each level.
How many times the process will be interrupted and in which queue,
process will complete execution?
1INT
Time quantum=7 9 31
Level 2
2INT
Time quantum=12 21 19
Level 3
3INT
Level Time quantum=17 38 02
4
4INT
Level 5 Time quantum=22 40 0
Execution Completed
Shared –memory system: