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

Assignment

CPU scheduling determines which process will use the CPU for execution. The main task is to ensure the CPU is not idle when processes are ready to run. Scheduling algorithms include preemptive and nonpreemptive, and examples like round robin, shortest job first, and priority scheduling. Different time quantums can improve multilevel queue performance. The dispatcher executes the selected process and handles context switching.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Assignment

CPU scheduling determines which process will use the CPU for execution. The main task is to ensure the CPU is not idle when processes are ready to run. Scheduling algorithms include preemptive and nonpreemptive, and examples like round robin, shortest job first, and priority scheduling. Different time quantums can improve multilevel queue performance. The dispatcher executes the selected process and handles context switching.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Assignment -3

Ques 1) What is CPU scheduling?


Answer:
CPU Scheduling is a process of determining which process will own CPU for
execution while another process is on hold. The main task of CPU scheduling is to
make sure that whenever the CPU remains idle, the OS at least select one of the
processes available in the ready queue for execution. The selection process will be
carried out by the CPU scheduler. It selects one of the processes in memory that are
ready for execution.
Ques 2) Define the difference between preemptive and nonpreemptive
scheduling.
Answer:
Parameter PREEMPTIVE SCHEDULING NON-PREEMPTIVE
SCHEDULING
Basic In this resources(CPU Cycle) Once resources(CPU Cycle) are
are allocated to a process for allocated to a process, the process
a limited time. holds it till it completes its burst
time or switches to waiting state.
Interrupt Process can be interrupted in Process can not be interrupted
between. until it terminates itself or its time is
up.
Starvation If a process having high If a process with a long burst time
priority frequently arrives in is running CPU, then later coming
the ready queue, a low priority process with less CPU burst time
process may starve. may starve.
Overhead It has overheads of It does not have overheads.
scheduling the processes.
Flexibility flexible rigid
Cost cost associated no cost associated
CPU In preemptive scheduling, It is low in non preemptive
Utilization CPU utilization is high. scheduling.
Examples Examples of preemptive Examples of non-preemptive
scheduling are Round Robin scheduling are First Come First
and Shortest Remaining Time Serve and Shortest Job First.
First.

Ques 3) What advantage is there in having different time-quantum sizes on


different levels of a multilevel queuing system?
Answer:
Processes that need more frequent servicing, for instance, interactive processes
such as editors, can be in a queue with a small time quantum. Processes with no
need for frequent servicing can be in a queue with a larger quantum, requiring
fewer context switches to complete the processing, and thus making more
efficient use of the computer.
Ques 4) Different types of Scheduling
Answer:
There are six popular process scheduling algorithms which we are going to discuss
in this chapter −

 First-Come, First-Served (FCFS) Scheduling


 Shortest-Job-Next (SJN) Scheduling
 Priority Scheduling
 Shortest Remaining Time
 Round Robin(RR) Scheduling
 Multiple-Level Queues Scheduling

First Come First Serve (FCFS)

 Jobs are executed on first come, first serve basis.


 It is a non-preemptive, pre-emptive scheduling algorithm.
 Easy to understand and implement.
 Its implementation is based on FIFO queue.
 Poor in performance as average wait time is high.

Wait time of each process is as follows −

Process Wait Time : Service Time - Arrival Time

P0 0-0=0

P1 5-1=4
P2 8-2=6

P3 16 - 3 = 13

Average Wait Time: (0+4+6+13) / 4 = 5.75

Shortest Job Next (SJN)

 This is also known as shortest job first, or SJF


 This is a non-preemptive, pre-emptive scheduling algorithm.
 Best approach to minimize waiting time.
 Easy to implement in Batch systems where required CPU time is known in
advance.
 Impossible to implement in interactive systems where required CPU time is
not known.
 The processer should know in advance how much time process will take.
Given: Table of processes, and their Arrival time, Execution time

Process Arrival Time Execution Time Service Time

P0 0 5 0

P1 1 3 5

P2 2 8 14

P3 3 6 8
Waiting time of each process is as follows −

Process Waiting Time

P0 0-0=0

P1 5-1=4

P2 14 - 2 = 12

P3 8-3=5

Average Wait Time: (0 + 4 + 12 + 5)/4 = 21 / 4 = 5.25

Priority Based Scheduling

 Priority scheduling is a non-preemptive algorithm and one of the most


common scheduling algorithms in batch systems.
 Each process is assigned a priority. Process with highest priority is to be
executed first and so on.
 Processes with same priority are executed on first come first served basis.
 Priority can be decided based on memory requirements, time requirements or
any other resource requirement.
Given: Table of processes, and their Arrival time, Execution time, and priority. Here
we are considering 1 is the lowest priority.
Process Arrival Time Execution Time Priority Service Time

P0 0 5 1 0

P1 1 3 2 11

P2 2 8 1 14

P3 3 6 3 5

Waiting time of each process is as follows −

Process Waiting Time

P0 0-0=0

P1 11 - 1 = 10

P2 14 - 2 = 12

P3 5-3=2

Average Wait Time: (0 + 10 + 12 + 2)/4 = 24 / 4 = 6


Shortest Remaining Time

 Shortest remaining time (SRT) is the preemptive version of the SJN


algorithm.
 The processor is allocated to the job closest to completion but it can be
preempted by a newer ready job with shorter time to completion.
 Impossible to implement in interactive systems where required CPU time is
not known.
 It is often used in batch environments where short jobs need to give
preference.

Round Robin Scheduling

 Round Robin is the preemptive process scheduling algorithm.


 Each process is provided a fix time to execute, it is called a quantum.
 Once a process is executed for a given time period, it is preempted and other
process executes for a given time period.
 Context switching is used to save states of preempted processes.

Wait time of each process is as follows −

Proces Wait Time : Service Time - Arrival Time


s

P0 (0 - 0) + (12 - 3) = 9

P1 (3 - 1) = 2

P2 (6 - 2) + (14 - 9) + (20 - 17) = 12

P3 (9 - 3) + (17 - 12) = 11
Average Wait Time: (9+2+12+11) / 4 = 8.5

Multiple-Level Queues Scheduling

Multiple-level queues are not an independent scheduling algorithm. They make use
of other existing algorithms to group and schedule jobs with common
characteristics.

 Multiple queues are maintained for processes with common characteristics.


 Each queue can have its own scheduling algorithms.
 Priorities are assigned to each queue.

Ques 5) Define Dispatcher.


Answer
A dispatcher is a special program which comes into play after the scheduler. When
the scheduler completes its job of selecting a process, it is the dispatcher which
takes that process to the desired state/queue. The dispatcher is the module that
gives a process control over the CPU after it has been selected by the short-term
scheduler. This function involves the following:
 Switching context
 Switching to user mode
 Jumping to the proper location in the user program to restart that
program

Ques 6) What is a Good Scheduler? Criteria


Answer:
Scheduling can be defined as a set of policies and mechanisms which controls the
order in which the work to be done is completed. The scheduling program which is a
system software concerned with scheduling is called the scheduler and the
algorithm it uses is called the scheduling algorithm.
Various criteria or characteristics that help in designing a good scheduling algorithm
are:
 CPU Utilization − A scheduling algorithm should be designed so that CPU
remains busy as possible. It should make efficient use of CPU.
 Throughput − Throughput is the amount of work completed in a unit of time.
In other words throughput is the processes executed to number of jobs
completed in a unit of time. The scheduling algorithm must look to maximize
the number of jobs processed per time unit.
 Response time − Response time is the time taken to start responding to the
request. A scheduler must aim to minimize response time for interactive
users.
 Turnaround time − Turnaround time refers to the time between the moment
of submission of a job/ process and the time of its completion. Thus how long
it takes to execute a process is also an important factor.
 Waiting time − It is the time a job waits for resource allocation when several
jobs are competing in multiprogramming system. The aim is to minimize the
waiting time.
 Fairness − A good scheduler should make sure that each process gets its
fair share of the CPU.
Ques 7) Explain Convoy effect.
Answer:

FCFS may suffer from the convoy effect if the burst time of the first job is the highest
among all. As in the real life, if a convoy is passing through the road then the other
persons may get blocked until it passes completely. This can be simulated in the
Operating System also.

If the CPU gets the processes of the higher burst time at the front end of the ready
queue then the processes of lower burst time may get blocked which means they
may never get the CPU if the job in the execution has a very high burst time. This is
called convoy effect or starvation.

Ques 8) Explain First-Come First-Served (FCFS) Scheduling and its advantage


and disadvantage.

Answer:

First-Come-First-Served algorithm is the simplest scheduling algorithm. Processes


are dispatched according to their arrival time on the ready queue. This algorithm is
always non preemptive, once a process is assigned to CPU, it runs to completion.
Advantages:
 more predictable than other schemes since it offers time
 code for FCFS scheduling is simple to write and understand
Disadvantages:
 Short jobs(process) may have to wait for long time
  Important jobs (with higher priority) have to wait
 cannot guarantee good response time
 average waiting time and turn around time is often quite long
  lower CPU and device utilization.

Ques 9) Explain Shortest-Job First Scheduling (SJF) and its advantage and
disadvantage.

Answer:

Characteristics of SJF Scheduling

 It is associated with each job as a unit of time to complete.


 This algorithm method is helpful for batch-type processing, where waiting for
jobs to complete is not critical.
 It can improve process throughput by making sure that shorter jobs are
executed first, hence possibly have a short turnaround time.
 It improves job output by offering shorter jobs, which should be executed first,
which mostly have a shorter turnaround time.

Advantages – 
1. Shortest jobs are favored.
2. It is provably optimal, in that it gives the minimum average
waiting time for a given set of processes.
Disadvantages – 
3. SJF may cause starvation, if shorter processes keep coming.
This problem is solved by aging.
4. It cannot be implemented at the level of short term CPU
scheduling.

Ques 10) Explain Priority Scheduling and its advantage and disadvantage.

Answer:

Priority Scheduling is a method of scheduling processes that is based on priority. In


this algorithm, the scheduler selects the tasks to work as per the priority.

The processes with higher priority should be carried out first, whereas jobs with
equal priorities are carried out on a round-robin or FCFS basis. Priority depends
upon memory requirements, time requirements, etc.

Advantages of priority scheduling

 Easy to use scheduling method


 Processes are executed on the basis of priority so high priority does not need
to wait for long which saves time
 This method provides a good mechanism where the relative important of each
process may be precisely defined.
 Suitable for applications with fluctuating time and resource requirements.

Disadvantages of priority scheduling

 If the system eventually crashes, all low priority processes get lost.
 If high priority processes take lots of CPU time, then the lower priority
processes may starve and will be postponed for an indefinite time.
 This scheduling algorithm may leave some low priority processes waiting
indefinitely.
 A process will be blocked when it is ready to run but has to wait for the CPU
because some other process is running currently.
 If a new higher priority process keeps on coming in the ready queue, then the
process which is in the waiting state may need to wait for a long duration of
time.
Ques 11) Explain Round-Robin Scheduling and its advantage and
disadvantage.

Answer:

The name of this algorithm comes from the round-robin principle, where each person
gets an equal share of something in turns. It is the oldest, simplest scheduling
algorithm, which is mostly used for multitasking.

In Round-robin scheduling, each ready task runs turn by turn only in a cyclic queue
for a limited time slice. This algorithm also offers starvation free execution of
processes.

Advantage of Round-robin Scheduling

 It doesn’t face the issues of starvation or convoy effect.


 All the jobs get a fair allocation of CPU.
 It deals with all process without any priority
 If you know the total number of processes on the run queue, then you can
also assume the worst-case response time for the same process.
 This scheduling method does not depend upon burst time. That’s why it is
easily implementable on the system.
 Once a process is executed for a specific set of the period, the process is
preempted, and another process executes for that given time period.
 Allows OS to use the Context switching method to save states of preempted
processes.
 It gives the best performance in terms of average response time.

Disadvantages of Round-robin Scheduling

 If slicing time of OS is low, the processor output will be reduced.


 This method spends more time on context switching
 Its performance heavily depends on time quantum.
 Priorities cannot be set for the processes.
 Round-robin scheduling doesn’t give special priority to more important tasks.
 Decreases comprehension
 Lower time quantum results in higher the context switching overhead in the
system.
 Finding a correct time quantum is a quite difficult task in this system.

Ques 12) Explain Multilevel Queue Scheduling and its advantage and
disadvantage.

Answer:

It may happen that processes in the ready queue can be divided into different
classes where each class has its own scheduling needs. For example, a common
division is a foreground (interactive) process and a background (batch) process.
These two classes have different scheduling needs. For this kind of situation
Multilevel Queue Scheduling is used. Now, let us see how it works. 
Ready Queue is divided into separate queues for each class of processes. For
example, let us take three different types of processes System processes,
Interactive processes, and Batch Processes. All three processes have their own
queue. Now, look at the below figure. 
Advantages – 
1. Application of separate scheduling for various kind of processes is
possible. 
 System Process – FCFS
 Interactive Process – SJF
 Batch Process – RR
 Student Process – PB
Disadvantages – 
1. The lowest level process faces starvation problem.

Ques 13) Explain Multilevel Feedback Queue Scheduling.

Answer:

In a multilevel queue-scheduling algorithm, processes are permanently assigned to a


queue on entry to the system. Processes do not move between queues. This setup
has the advantage of low scheduling overhead, but the disadvantage of being
inflexible.

Multilevel feedback queue scheduling, however, allows a process to move between


queues. The idea is to separate processes with different CPU-burst characteristics. If
a process uses too much CPU time, it will be moved to a lower-priority queue.
Similarly, a process that waits too long in a lower-priority queue may be moved to a
higher-priority queue. This form of aging prevents starvation.

Advantages – 
1. Low scheduling overhead.
2. Allows aging, thus no starvation.
Disadvantages – 
1. It’s not flexible.
2. It also requires some means of selecting values for all the parameters to
define the best scheduler, thus it is also the most complex.

Ques 14)
Consider the following set of processes:

Process Arrival Time Burst Time


P1 0 3
P2 2 6
P3 4 4
P4 6 5
P5 8 2
Calculate waiting time, average waiting time, and turnaround time.
I. FCFS
II. SJF
III. SRTF

Answer:
Ques 15)
Consider the following set of processes:
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
Calculate waiting time, average waiting time, and turnaround time.
I.FCFS
II.SJF
III.SRTF

Answer:
Ques 16)
Consider the following set of processes:

Process CPU Burst Priority


P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2
Calculate waiting time, average waiting time, and turnaround time.
I. FCFS
II. SJF
III. SRTF
IV. Priority

Answer:
Ques 17)
Consider the following set of processes:
Process Burst Time
P1 53
P2 17
P3 68
P4 24
Time Quantum: 20
Calculate waiting time, average waiting time, and turnaround time.
I. FCFS
II. SJF
III. SRTF
IV. Round Robbin
Answer:

You might also like