Вы находитесь на странице: 1из 6

Assignment No: 1

Assignment Title: CPU Scheduling

1
Assignment Statement:
Write a menu driven program to implement following CPU scheduling algorithms
1) First come First Serve (FCFS)
2) Shortest Job First (SJF) (Preemptive and non_preemptive)
3) Round Robin (RR)
4) Priority (Preemptive and non_preemptive)
Objectives:
To study the Need for CPU scheduling
To study the comparative study of various CPU scheduling methods
Implementation of CP U Scheduling
Theory:
Need: In multiprogramming environment, multiple processes are maintained in the main
memory. Each process alternates between the using a processor and waiting for I/O to be
completed or for some other event to occur. The processor is kept busy by executing one
process while others wait. The key to multiprogramming is Scheduling. The aim of
Processor scheduling is to assign processes to be executed by the processor over time, in
such a way that meets the system objectives, such as response time, throughput and
processor efficiency.

Types of Scheduling:
Long Term Scheduling: It is invoked when new process is created. This decides
whether to add a new process to the set/pool of processes that are currently active. It
controls the degree of multiprogramming
Medium Term Scheduling: It is a part of swapping function. The decision is taken
whether to add a process to those that are partially or fully available in memory and
therefore available for execution.
Short Term Scheduling: It is the actual decision of which ready processes will be
executed by the processor.
1) First Come First Serve (FCFS):-
This is the simplest CPU scheduling algorithm. It is also known as first in first out (FIFO)
or a strict queuing scheme. As each process becomes ready, it is added at the rear end of
queue. When currently running process finishes, it is removed from the queue and the
next process in the ready queue is selected for execution. FCFS performs much better for
longer processes( having larger CPU burst time).

Characteristics:
Selection Function: max(w), selects the process which is waiting in the ready queue
for maximum time.
Decision Mode : Non_preemptive
Throughput: Not emphasized
Response Time: May be high, especially if there is a large variance in the process
execution times.
Overhead: Minimum
Effect on Processes: Penalizes short and I/O bound processes.
Starvation: No

2
2) Shortest Job First/ Shortest Process Next (SJF/SPN) :- This is a non-preemptive
policy in which the process with the shortest expected processing time is selected next.
Thus a short process will jump to the head of the queue. This type of policy needs to know
or at least estimate the required processing time of each process.
Characteristics:
Selection Function: minimum total service time required by the process, including
time spent in execution so far.
Decision Mode : Non_preemptive
Throughput: High
Response Time: Provides good response time for short processes.
Overhead: Can be high
Effect on Processes: Penalizes long processes.
Starvation: Possible

3) Shortest Job First Preemptive or Shortest Remaining Time: It is a preemptive version


of SJF. In this policy, scheduler always chooses the process that has the shortest expected
remaining processing time. When a new process arrives in the ready queue, it may in fact
have a shorter remaining time than the currently running process. Accordingly, the
scheduler may preempt whenever a new process becomes ready. Scheduler must have an
estimate of processing time to perform the selection function.
Characteristics:
Selection Function: minimum total service time required by the process, minus time
spent in execution so far.
Decision Mode : Preemptive ( At arrival time)
Throughput: High
Response Time: Provides good response time
Overhead: Can be high
Effect on Processes: Penalizes long processes.
Starvation: Possible

4) Round Robin (RR) :-


This algorithm is especially implemented for time sharing systems . It is similar to FCFS
but preemption is added to switch between processes. A small unit of time called as Time
Quantum is defined ( 10 to 100 milliseconds ) . The ready queue is treated as a circular
queue. The CPU scheduler move along the queue allocating the CPU to each process for a
time interval of upto 1 quantum . New processes are added to the tail of the queue . The
average waiting time is often quite long. It is preemptive . The algorithms performance
heavily depends upon the time quantum, and so thus the turnaround time . It degenerates
to FCFS if time quantum is large.

Selection Function: Constant


Decision Mode : Preemptive ( At time quantum)
Throughput: May be low if time quantum is too small
Response Time: Provides good response time for short processes.
Overhead: minimum
Effect on Processes: Fair treatment
Starvation: No

3
Algorithm : To be written by individual student as per the logic used

Data Structure Used:- Queue implemented using linked list and for Round Robin Circular
linked List

Input-Output along with test cases

1) For all : Give input such that the processes are not entered as per the arrival time.
2) For all: CPU remains idle
3) For preemptive : Accept input in such a manner that processes get preempted
Round Robin :Test case I
No. Of. Processes: 5
name arrival burst
time time
a 0 1
b 2 1
c 4 2
d 6 3
e 8 2
Enter time quantum for round robin method: 2

Process a executes from 0 to 1


CPU remains IDLE from 1 to 2
Process b executes from 2 to 3
CPU remains IDLE from 3 to 4
Process c executes from 4 to 6
Process d executes from 6 to 8
Process e executes from 8 to 10
Process d executes from 10 to 11

Gant chart
a b c d e d
<0 to 1><2 to 3><4 to 6><6 to 8><8 to 10><10 to 11>

Total chart
name arrival finish burst waiting Turnaround
time time time time time
a 0 1 1 0 1
b 2 3 1 0 1
c 4 6 2 0 2
e 8 10 2 0 2
4
d 6 11 3 2 5
Round Robin Test Case 2
name arrival burst
time time
a 0 2
b 1 2
c 2 2
d 7 2
e 8 2
Enter time quantum for round robin method: 1

Process a executes from 0 to 1


Process b executes from 1 to 2
Process a executes from 2 to 3
Process c executes from 3 to 4
Process b executes from 4 to 5
Process c executes from 5 to 6
CPU remains IDLE from 6 to 7
Process d executes from 7 to 8
Process e executes from 8 to 9
Process d executes from 9 to 10
Process e executes from 10 to 11
Gant chart
a b a c b c d e d e
<0 to 1><1 to 2><2 to 3><3 to 4><4 to 5><5 to 6><7 to 8><8 to 9><9 to 10><10 to 11>

Total chart
name arrival finish burst waiting Turnaround
time time time time time
a 0 3 2 1 3
b 1 5 2 2 4
c 2 6 2 2 4
d 7 10 2 1 3
e 8 11 2 1 3

Platform :- MS – DOS /LINUX

Language:- C - Programming Language / C++

FAQ’s :-

(1) What is meant by CPU scheduling?


(2) What are different types of schedulers ?
(3) What is preemptive & non - preemptive scheduling ?
(4) What is i/o burst and CPU burst ?
(5) Define the following terms :
(1)Turnaround Time :
(2)Waiting Time :
(3)Response Time :

5
6

Вам также может понравиться